【发布时间】:2022-12-18 11:58:06
【问题描述】:
我正在使用 spring-data-jpa 这是我的查询
@Query(value = "select ea.* from employee ea where ids in (?1) and (?2 is null or country=?2) ", nativeQuery = true)
Page<Employee> findByds(List<UUID> ids,String country ,Pageable pageable );
我只想在参数country 不为空时通过匹配国家/地区获取员工列表,否则我想获取iDs 中的所有记录
SQL 查询在国家/地区参数为空的情况下不起作用。我希望我的查询像
-
当国家为空时
select ea.* from employee ea where ids in (?1) -
当国家不为空时
select ea.* from employee ea where ids in (?1) and country =?2
【问题讨论】:
-
将 (?2 is null or country=?2) 更改为 (country is null or country=?2)
-
(country is null or country=?2)仅返回具有null值的记录
标签: java sql spring postgresql spring-boot