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都支持