【发布时间】:2016-08-18 16:56:03
【问题描述】:
我正在使用带有 spring 数据的 spring boot,特别是扩展 CrudRepository 的类 PagingAndSortingRepository。
我需要一个查询,如果匹配四个列表中的任何一个,则返回表的所有条目,当它为空(或空)时忽略它。
如果我使用 findByTypeInAndLocaleInAndCategoryInAndTagIn 并且其中一个列表为空,则结果也为空。所以我最终写了几个查找器,并根据哪些列表是空的,使用不同的。
是否可以将其合并到一个查找器中?
例如如果我使用 findByTypeAndLocale,如果列表类型为空,我想匹配所有类型的值。
对任何提示都很满意。
@Repository
public interface FeedRepository extends PagingAndSortingRepository<FeedEntry, Long>, JpaSpecificationExecutor<FeedEntry> {
public List<FeedEntry> findByGuid(String guid);
public Page<FeedEntry> findAll(Pageable pageable);
public Page<FeedEntry> findByLocale(List<LocaleEnum> type, Pageable pageable);
public Page<FeedEntry> findByType(List<FeedTypeEnum> type, Pageable pageable);
public Page<FeedEntry> findByTypeAndLocale(FeedTypeEnum type, LocaleEnum locale, Pageable pageable);
public Page<FeedEntry> findByTypeInAndLocaleIn(List<FeedTypeEnum> type,List<LocaleEnum> locale, Pageable pageable);
public Page<FeedEntry> findByTypeInAndLocaleInAndCategoryIn(List<FeedTypeEnum> type,List<LocaleEnum> locale, List<String> category, Pageable pageable);
public Page<FeedEntry> findByTypeInAndLocaleInAndTagIn(List<FeedTypeEnum> type,List<LocaleEnum> locale, List<String> tag, Pageable pageable);
public Page<FeedEntry> findByTypeInAndLocaleInAndCategoryInAndTagIn(List<FeedTypeEnum> type,List<LocaleEnum> locale, List<String> category, List<String> tag, Pageable pageable);
}
【问题讨论】:
标签: spring spring-boot spring-data-jpa crud