【发布时间】:2016-03-28 12:41:17
【问题描述】:
我的要求是:
- 如果
createrIds为空,则搜索所有数据 - 如果
createrIds不为空,则匹配数据
以下代码不起作用,我该如何解决?
@Query("from CommodityEntity e where (:createrIds is null or e.createrEntity.id in :createrIds)" )
Page<CommodityEntity> searchByCreaterAndPage( @Param("createrIds") List<Long> createrIds,Pageable pageable);
【问题讨论】:
-
请描述您使用当前代码遇到的错误。
-
这是生成的 sql::createrIds_0_, :createrIds_1_, :createrIds_2_, :createrIds_3_ IS NULL OR e.createrEntityId IN :createrIds_0_, :createrIds_1_, :createrIds_2_, :createrIds_3_
-
JPQL 应该以“SELECT e”开头。还要将 ":createrIds" 放在括号 "(:createrIds)" 中,因为一些 JPA 实现需要它(尽管其他实现不需要)