Mybatis模糊查询和根据日期筛选查询
这里我选择简单的方式进行操作,模糊查询我使用字符串拼接的方式,日期筛选通过gt lt转义符拼接判断,实现方式肯定不止这一条,会继续补充完善
模糊查询,关键代码如下
<if test="name!=null and name!=''">
and ds.name like concat('%', #{name}, '%')
</if>
日期筛选,关键代码如下
注意:gt lt 都要加&,后面跟; 格式别错了
<if test="startDate!=null and startDate!='' and stopDate!='' and stopDate!=null" >
and ds.confirm_time > #{startDate} and ds.confirm_time < #{stopDate}
</if>
一些常见的转义符
eq == equal 等于
ne == not equal 不等于
gt == greater than 大于
lt == less than 小于
ge == greater than or equal 大于等于
le == less than or equal 小于等于
in == in 包含(数组)
isNull == 等于null
isNotNull == 不等于null
orderByDesc == 倒序排序
orderByAsc == 升序排序
or == 或者
and == 并且
between == 在2个条件之间(包括边界值)
like == 模糊查询
clear == 清除
apply == 拼接sql
lambda == 使用lambda表达式
exists == 临时表