这是我的代码,不论 ids 列表为不为空,都会报错
@Query(""" SELECT SUM(age) FROM user where (:ids IS NULL OR id in (:ids)) """) Mono<Long> sumAges(List<Long> ids);
下面这个当 ids 列表不为时不报错
@Query(""" SELECT SUM(age) FROM user where (concat(', :ids,') = '()' OR id in (:ids)) """) Mono<Long> sumAges(List<Long> ids);
我该怎么改呀,我知道可以在 service 层判断列表空直接返回 Mono.just(0L),但是还有其他许多参数需要判断时呢,总不能疯狂定制方法
![]() | 1 RedBeanIce 2023-03-31 18:37:37 +08:00 请贴一下最终打印的 sql ,或许你就明白了。 |
2 kwh 2023-03-31 18:48:57 +08:00 :ids IS NULL 能这么写吗? column is NULL 吗?能写 Object is NULL??? |
![]() | 4 goalidea 2023-04-09 10:56:31 +08:00 1 楼是正确处理问题的方法 |