mybatis 之 if test 条件
2017-12-14 22:22
183 查看
问题描述:mybatis 之 if test 条件,参数为0时,查询条件未输出。如,当 tagtype值为0(Integer),查询条件没有拼接 and tagtype=0。传入其他值(1,2,3...)都正常
一、mybatis 配置
<!-- Where查询条件 -->
<sql id="whereSQL">
<if test=" null != id">
AND id =#{id}
</if>
<if test=" null != tagname and '' != tagname">
AND tagname LIKE '%${tagname}%'
</if>
<if test=" null != tagtype and '' != tagtype">
AND tagtype = #{tagtype}
</if>
</sql>
二、表结构
解决方法:
将
<if test=" null != tagtype and '' != tagtype">
AND tagtype = #{tagtype}
</if>
修改为
<if test=" null != tagtype and '' != tagtype or 0 == tagtype">
AND tagtype = #{tagtype}
</if>
一、mybatis 配置
<!-- Where查询条件 -->
<sql id="whereSQL">
<if test=" null != id">
AND id =#{id}
</if>
<if test=" null != tagname and '' != tagname">
AND tagname LIKE '%${tagname}%'
</if>
<if test=" null != tagtype and '' != tagtype">
AND tagtype = #{tagtype}
</if>
</sql>
二、表结构
解决方法:
将
<if test=" null != tagtype and '' != tagtype">
AND tagtype = #{tagtype}
</if>
修改为
<if test=" null != tagtype and '' != tagtype or 0 == tagtype">
AND tagtype = #{tagtype}
</if>
相关文章推荐
- mybatis 之 if test 条件
- 使用mybatis遇到的关于条件查询">"以及if test传参的使用问题
- mybatis 之 if test 条件
- mybatis if test加筛选条件
- myBatis查询某个时间区间数据<if test=""> 如何写判断条件,and 里面的内容怎么写?
- MyBatis 判断条件为等于的问题(<if test="type == '1'.toString()"> xxx </if>
- mybatis的<if test> 条件判断
- mybatis的<if test> 条件判断
- mybatis 之 if test 条件
- mybatis 之 if test 条件,参数为0时,查询条件未输出
- <c:if test=" ${cppc.hpid==hpcc.id}">条件判断
- MyBatis if test 字符串判断问题
- mybatis 里面使用<if test=""> 判断,当后台传的值是数字字符串时,怎么处理
- mybatis String的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- mybatis if条件判断字符串类型是否一致
- mybatis if test 不为空字符串或null
- Mybatis的if test字符串比较问题
- Mybatis if test 判断数字时需要注意
- mybatis模糊查询及if多条件(if条件的参数为方法参数而非数据库字段)
- mybatis **-mapping.xml文件中if test表达式逻辑判断“并且”,不能用&&