如果字段为空不更新、字段不为空做更新,springData如何去实现?
类似mybaits
whereid=#{id}
<if test="createTimeStart!=null">
AND p.create_time >= #{createTimeStart}
</if>
<if test="createTimeEnd!=null">
AND p.create_time <= #{createTimeEnd}
</if>
类似mybaits
whereid=#{id}
<if test="createTimeStart!=null">
AND p.create_time >= #{createTimeStart}
</if>
<if test="createTimeEnd!=null">
AND p.create_time <= #{createTimeEnd}
</if>
2017-08-17
可以看看这两种方法: (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);
举报