【发布时间】:2021-08-08 13:10:07
【问题描述】:
我有 2 节课。请求和服务类。
请求类。
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;
}
}
现在我在 Service 类中使用 ManyToMany 获得 serviceName。 但我无法获得另一个值。我需要在没有 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 当我做 request.service 时,这只会出现 serviceName,因为我在这里写 toString 方法返回 this.serviceName 。我可以用 toString 方法得到所有这些。但我需要单独。
【问题讨论】:
-
你想做什么?我不明白
-
@Zaur mən 服务类-ını 请求类-ında istifadə etmişəm və 请求yaradanda olan servisləri seçirəm。 O servisləri görmək üçün də, request.service 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 çağıra bilim。 Çünki request.service yazanda yalnız toString ilə yazdığım qayıdır。 Amma mənə ayrı-ayrılıqda lazımdır.
-
qardas sen reuqest.service.getServiceName yazib cagirandada hamisi gelir ?
-
he basa dusdum eziz
-
getter evezine sen onu bri basa yazirsan
标签: java spring-boot jpa orm spring-data-jpa