mybatis if null
- 作者: 真的有那么难吗
- 来源: 51数据库
- 2020-09-29
<where>
<trim prefixOverrides="and">
<if test="id!=null">
and c.id=#{id}
</if>
<if test="oid!=null and oid!=0">
and b.id=#{oid}
</if>
<if test="startDate!=null">
<if test="endDate!=null">
and a.pay_time BETWEEN #{startDate} AND #{endDate}
</if>
</if>
</trim>
</where>
service层如果参数为null,mybatis执行sql语句的时候就不会去拼接你指定的if标签中的sql语句
<trim prefixOverrides="and">
<if test="id!=null">
and c.id=#{id}
</if>
<if test="oid!=null and oid!=0">
and b.id=#{oid}
</if>
<if test="startDate!=null">
<if test="endDate!=null">
and a.pay_time BETWEEN #{startDate} AND #{endDate}
</if>
</if>
</trim>
</where>
service层如果参数为null,mybatis执行sql语句的时候就不会去拼接你指定的if标签中的sql语句
推荐阅读
