我需要在一個請求中獲取有關票證的所有資訊,以及書名、作者和年份。我已經實作了這個:我創建介面TicketWithBookView
public interface TicketWithBookView {
Date getGiveAway();
Long getReaderId();
Date getTake();
interface Book {
String getAuthor();
String getName();
Integer getYearCreation();
}
}
我的物體TicketEntity
@Data
@Entity
@Table(name = "ticket")
@NoArgsConstructor
@AllArgsConstructor
public class TicketEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private Long readerId;
@Column(nullable = false)
private Long bookId;
@Column(nullable = false)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date take;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date giveAway;
}
第二個物體BookEntity;
@Entity
@Data
@NoArgsConstructor
@Table(name = "book")
public class BookEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String author;
private Integer yearCreation;
private Integer count;
}
和存盤庫
@Repository
public interface TicketRepository extends CrudRepository<TicketEntity, Long> {
List<TicketWithBookView> findAllByGiveAwayIsNullAndTakeIsNotNull();
}
uj5u.com熱心網友回復:
沒辦法)投影用于從查詢中選擇資料,而不是從其他表中獲取資料。您可以從另一個上傳資料table并model在service.
uj5u.com熱心網友回復:
可能問題出AAnd在方法名稱上
findAllByGiveAwayIsNull AAnd AndTakeIsNotNull
添加您收到的錯誤訊息,這樣會更容易找到問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/464627.html
