Mybatis的if test字符串比较问题,mapper用等于又要用>比较

第一种解决方法:

<if test="isExpired=='Y'">
and msg.expire_time < now()
if>
会报NumberFormatException,这样就可以了。
<if test="isExpired=='Y'.toString()">
and msg.expire_time < now()
if>

第二种解决方法

<if test=" name=='你好' ">

<if>

这样会有问题,换成

<if test=' name=="你好" '>

<if>

实际用到的地方是这样的
当一个条件既要用到等于又要用到>等判断的时候这样做

  <if test="_parameter.containsKey('colNum') and colNum!='6'.toString()" >
            and a.col_num = #{colNum}
        if>
 <if test="_parameter.containsKey('colNum') and colNum =='6'.toString()" >
            and (a.col_num+0) > 5
        if>

非常方便

如果用<号 会冲突和,是这样解决的

  
            and a.send_area_name <#{sendAreaName} 
        ]]>

把if包在里面就好了

你可能感兴趣的:(eclispe,j2ee,数据库)