mybatis test标签判断值是否相等

mybatis可以很方便生成动态sql,常用的方式如下:

        <if test="id != null and id !=''">
            and id != #{id}     
        </if>   

但是在实际使用过程中可能会需要对某个输入的值做具体判断,然后根据输入参数的值进行分支处理

<select id="xxxx" parameterType="map" resultMap="BaseResultMap"> 

         。。。。。。。

     <choose>
               <when test="hasAttach.toString() == '1'.toString()">
                   having  attachCount &gt;= #{hasAttach}
               </when>
               <otherwise>
                   having  attachCount = #{hasAttach}
               </otherwise>
           </choose>

鉴于这个mapper查询接口传入的参数为Map<String,Object>类型,如果不进行toString的转换的话默认是对进行进行的对比,因此就无法达到预期的比较字符串的效果。

猜你喜欢

转载自blog.csdn.net/john1337/article/details/81083694
今日推荐