我有一个使用Spring Boot的简单REST服务,它使用CrudRepository
访问数据。
这个仓库已经实现了分页和排序功能,就像这样:
public interface FlightRepository extends CrudRepository<Flight, Long> {
List<Flight> findAll(Pageable pageable);
}
叫它:
Sort sort = new Sort(direction, ordering);
PageRequest page = new PageRequest(xoffset, xbase, sort);
return flightRepo.findAll(page);
我希望在这个存储库中添加筛选功能(例如仅返回带有id > 13 AND id < 27
的实体)。 CrudRepository似乎不支持此功能。是否有某种方法可以实现这一点,还是我需要使用不同的方法?谢谢任何提示!
List<Flight> findByIdBetween(Long start, Long end, Pageable pageable)
。 - pezetemPagingAndSortingRepository
。 - Jos