我的商店物體中有一個具有以下關系的物體:
@OneToMany(mappedBy="computer")
@JsonProperty("computers")
public Set<Computer> computers;
在我的 StoreService 中:
List<Computers> computers;
Pageable paging = PageRequest.of(page, size);
Page<Computers> pageTuts;
pageTuts = storeRepository.findAllComputers(paging);
computers = pageTuts.getContent();
Map<String, Object> response = new HashMap<>();
response.put("computers", computers);
response.put("current_page", pageTuts.getNumber());
response.put("total_items", pageTuts.getTotalElements());
response.put("total_pages", pageTuts.getTotalPages());
現在我需要以某種方式在我的StoreRepository介面中查詢與該物體相關的所有計算機。我怎樣才能做到這一點?我以為我可以添加這樣的名稱:
Page<Computers> findAllComputers(Pageable pageable);
任何想法如何解決這個問題?我是否必須撰寫自定義查詢或其他內容?我認為這個操作應該是某種標準,所以很難認為我會需要它。
uj5u.com熱心網友回復:
您應該創建ComputerRepository這種方法并將其添加到您的存盤庫類中。
public interface ComputerRepository extends PagingAndSortingRepository<Computer, Integer> {
Page<Computers> findByStore(Store store, Pageable pageable);
}
這是對分頁和排序的快速解釋。
https://www.baeldung.com/spring-data-jpa-pagination-sorting
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/451694.html
上一篇:如何在Hibernate中使用application.properties設定配置?
下一篇:SpringBoot中的@ManyToMany(無法延遲初始化角色集合:com.example.demo.Movie.actors,無法初始化代理-無會話)
