用户登录
用户注册

分享至

mybatis xml if or

  • 作者: 骚年应该有内涵
  • 来源: 51数据库
  • 2020-10-01
在项目中xml文件经常会遇到在判断等于某个值时加什么条件不等于某个值的时候加什么条件,比如下面这个例子:
<if test=" name != null">
AND T.NAME = #{NAME,jdbcType=VARCHAR}
</if>
<if test=" name = null">
ORDER BY NAME,ID
</if>

上面这个例子是一个错误的写法不可以这样用。
正确的需要引入<choose>标签
<choose>
<when test=" name != null">
AND T.NAME = #{NAME,jdbcType=VARCHAR}
</when>
<otherwise>
ORDER BY T.PRODUCT_TYPE_CODE, T.SORT DESC, T.CREATE_TIME
</otherwise>
</choose>
软件
前端设计
程序设计
Java相关