0
点赞
收藏
分享

微信扫一扫

jap @Query多条件灵活查询

快乐小鱼儿_9911 2022-03-26 阅读 128
javaspring

1. MySQL使用if进行条件判空



@Query(nativeQuery=true,value="select * from company where if(:code is not null and :code != '' , code =:code,1=1)")
List<Company> getCompanyList(@Param("code") String code);


2. 使用case when 进行条件判空


@Query(value = "select * from company where (1=(case when :code is null then 1 else 0 end) or code =:code ))",nativeQuery = true)
List<Company> getCompanyList(@Param("code") String code);

测试sqlServer和mysql都支持

举报

相关推荐

0 条评论