类似mybaits
whereid=#{id}
<if test="createTimeStart!=null">
AND p.create_time >= #{createTimeStart}
</if>
<if test="createTimeEnd!=null">
AND p.create_time <= #{createTimeEnd}
</if>
可以看看这两种方法: (1)@Query( value = "SELECT * FROM sys_customer WHERE 1=1 " + " AND if(:name!='',name LIKE CONCAT('%',:name,'%'),1=1)", nativeQuery = true) (2)@Query(value = "SELECT * FROM sys_customer WHERE 1=1 "+ " AND (name LIKE CONCAT('%',:name,'%') OR :name IS NULL )", nativeQuery = true) List<Customer> findDate(@Param("name") String name);