Java 当我使用@ManyToMany时,如何获得另一个类的价值
我有两节课。请求和服务类 要求上课Java 当我使用@ManyToMany时,如何获得另一个类的价值,java,spring-boot,jpa,orm,spring-data-jpa,Java,Spring Boot,Jpa,Orm,Spring Data Jpa,我有两节课。请求和服务类 要求上课 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 = &q
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;
}
}
现在我在服务类中获得了serviceName和ManyToMany。
但我不能得到另一个值。我需要在不使用字符串的情况下执行此操作
<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>
请求详细信息
&时代;
西法里·穆马塔拉里
西法里德
凯迪亚特塔里希
希德姆ət
Təhvil verməzamanı
雷伊
地位
巴奥拉
当我这样做的时候,我不能得到价值
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:text="${request.service.serviceCategory}"></td>
</tr>
希德姆ət
或
希德姆ət
我怎么能做到?如何获取request.service.serviceCount或serviceCategory或serviceName
当我执行request.service时,只有这个serviceName,因为我在这里写toString方法返回这个serviceName。我可以用toString方法得到所有这些。但我需要单独使用。这是我的百里香示例
<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>
身份证
身份证作者
标题
@GetMapping(“/requests/view/{requestId}”)
公共字符串requestDetails(@PathVariable(value=“requestId”)长requestId,Model){
Requests-request=requestService.getRequestById(requestId);
List listClients=clientService.getAllClients();
List listServices=serviceRepository.findAll();
model.addAttribute(“listServices”,listServices);
model.addAttribute(“ListClient”,ListClient);
model.addAttribute(“请求”,请求);
返回“请求\详细信息\模式”;
}
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>
希德姆ət
您想做什么?我没有understand@Zaurmən服务类-nını请求类-ında istifadəetmişm və请求yaradanda olan servisləri seçirəm。O servisləri görməküçn də,请求服务yazıbçağrıram。amma mənəlazımdır ki,request.service.serviceName vəya request.service.serviceCategory hamısın ayrılıqdağra bilim。钦基请求。亚赞达·亚尔内斯向伊尔亚兹德·卡伊·迪尔提供服务。Amma mənəayrılıqda lazır.qardas sen reuqest.service.getservicenam yazib Cagiranda hamisi gelir?他是一位来自于埃齐兹格特的年轻人,他是一位来自亚齐尔萨尼尼的年轻人,他是一位来自亚齐尔萨尼尼的年轻人。乔克斯·萨奥尔·克莫伊恩。布努亚兹尔德姆·波祖尔德姆,çnki qırmızılayırdıBunu intellij,deyirdim düz deyiı。他经营着埃特米迪姆。运行etdim alındıD。乔克斯·萨奥尔·特克莱尔·科姆·伊因çn。斯普林-伊尔克·普罗耶克蒂姆迪,泽里西尔·林·德尔斯利克勒·林德·埃尔卡·马尔·汉斯·德萨·蒂迪,奥纳·戈尔姆·昂丹·伊斯蒂法德·埃德姆·格迪姆
<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>
@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";
}
<tr>
<th scope="col">Xidmət</th>
<td data-label="Xidmət" th:field="*{service}" th:text="{}"></td>
</tr>