我有两个班。请求和服务类。
请求类。
import com.eziz.clients.Clients;
import com.eziz.services.Services;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@Table(name = "request")
public class Requests {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long requestId;
@Column(nullable = false, length = 80)
private String requestComment;
@Column(nullable = false, length = 15)
private String requestStatus;
@DateTimeFormat(pattern = "dd-MM-yyyy")
@Column(nullable = false)
private String requestExpiryTime;
@DateTimeFormat(pattern = "dd-MM-yyyy")
@Column(nullable = false)
private String requestDateCreated;
@ManyToOne
@JoinColumn(name = "requestClientId")
private Clients client;
@ManyToMany
@JoinColumn(name = "requestServiceId")
private Set<Services> service = new HashSet<>();
// @ManyToOne
// @JoinColumn(name = "requestService")
// private Services services;
//
public Long getRequestId() {
return requestId;
}
public void setRequestId(Long requestId) {
this.requestId = requestId;
}
public String getRequestComment() {
return requestComment;
}
public void setRequestComment(String requestComment) {
this.requestComment = requestComment;
}
public String getRequestStatus() {
return requestStatus;
}
public void setRequestStatus(String requestStatus) {
this.requestStatus = requestStatus;
}
public String getRequestExpiryTime() {
return requestExpiryTime;
}
public void setRequestExpiryTime(String requestExpiryTime) {
this.requestExpiryTime = requestExpiryTime;
}
public String getRequestDateCreated() {
return requestDateCreated;
}
public void setRequestDateCreated(String requestDateCreated) {
this.requestDateCreated = requestDateCreated;
}
public Clients getClient() {
return client;
}
public void setClient(Clients client) {
this.client = client;
}
public Set<Services> getService() {
return service;
}
public void setService(Set<Services> service) {
this.service = service;
}
}
服务班。
package com.eziz.services;
import javax.persistence.*;
@Entity
@Table(name = "service")
public class Services {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long serviceId;
@Column(nullable = false, length = 20)
private String serviceName;
@Column(nullable = false, length = 30)
private String serviceCategory;
@Column(nullable = false)
private double servicePrice;
public Long getServiceId() {
return serviceId;
}
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getServiceCategory() {
return serviceCategory;
}
public void setServiceCategory(String serviceCategory) {
this.serviceCategory = serviceCategory;
}
public double getServicePrice() {
return servicePrice;
}
public void setServicePrice(double servicePrice) {
this.servicePrice = servicePrice;
}
@Override
public String toString() {
return this.serviceName;
}
}
现在,我在服务类中获得了serviceName和ManyToMany。但是我不能再得到其他的价值了,没有toString,我就需要这样做。
<div class="modal header">
<h5 class="modal-title" id="modalTitle">Request Details</h5>
<button aria-label="Close" class="close" data-dismiss="modal"
type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="content content-fixed content-auth">
<div class="container">
<h1 class="tx-color-01 mg-b-5" align="center">
SIFARIŞ MƏLUMATLARI </h1>
<hr>
<table class="table">
<tr th:object="${request}">
<tr>
<th scope="col">Sifariş ID</th>
<td scope="col" data-label="Sifariş ID" th:text="${request.requestId}"></td>
</tr>
<tr>
<th scope="col">Qeydiyyat tarixi</th>
<td data-label="Qeydiyyat tarixi" th:text="${request.requestDateCreated}"></td>
</tr>
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:text="${request.service}"></td>
</tr>
<tr>
<th scope="col">Təhvil vermə zamanı</th>
<td data-label="Təhvil vermə zamanı" th:text="${request.requestExpiryTime}"></td>
</tr>
<tr>
<th scope="col">Rəy</th>
<td data-label="Rəy" th:text="${request.requestComment}"></td>
</tr>
<tr>
<th scope="col">Status</th>
<td data-label="Status" th:text="${request.requestStatus}"></td>
</tr>
</tr>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Bağla</button>
</div>
当我这样做的时候,我无法得到价值。
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:text="${request.service.serviceCategory}"></td>
</tr>
或
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:text="${request.service.serviceCount}"></td>
</tr>
我怎么能这么做?当我做request.service.serviceCount、serviceCategory或serviceName时,如何才能得到serviceName,因为我在这里编写toString方法返回this.serviceName。我可以使用toString方法获得所有这些信息。但我需要分开。
发布于 2021-05-19 23:23:12
这是我的Thymeleaf例子
<p>
<span th:each="task : ${foo.tasks}">
<span th:text="${taskStat.index} + ': ' + ${task.name}"></span>
</span>
</p>
<tr th:each="book : ${listBooksTest}">
<td th:text="${book.id}">ID Book</td>
<td th:text="${book.id_author}">ID Author</td>
<td th:text="${book.title}">Title</td>
</td>
</tr>
发布于 2021-05-19 23:24:33
@GetMapping("/requests/view/{requestId}")
public String requestDetails(@PathVariable(value = "requestId") long requestId, Model model) {
Requests request = requestService.getRequestById(requestId);
List<Clients> listClients = clientService.getAllClients();
List<Services> listServices = serviceRepository.findAll();
model.addAttribute("listServices", listServices);
model.addAttribute("listClients", listClients);
model.addAttribute("request", request);
return "request_detail_modal";
}
Yuxarıda list kimi gətirmişəm,onu burada td-əgətirmək lazımdı.
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:field="*{service}" th:text="{}"></td>
</tr>
https://stackoverflow.com/questions/67600745
复制相似问题