mapper文件中if标签中字符串的比较,当使用"=="和"!="来判断时注意如下细节:
正确方式一:
<select id="queryList" parameterType="map" resultType="map">
SELECT sys_user.id_, sys_user.name_ FROM sys_user
<where>
<if test='classify_!= null and classify_!= ''and classify_== "3"'>
AND sys_user.name_ like CONCAT('%',#{descript},'%')
</if>
</where>
</select>
正确方式二:(单双引号的使用)
<select id="queryList" parameterType="map" resultType="map">
SELECT sys_user.id_, sys_user.name_ FROM sys_user
<where>
<if test="classify_!= null and classify_!= '' and classify_== '3'.toString()">
AND sys_user.name_ like CONCAT('%',#{descript},'%')
</if>
</where>
</select>
错误方式:
<select id="queryList" parameterType="map" resultType="map">
SELECT sys_user.id_, sys_user.name_ FROM sys_user
<where>
<if test="classify_!= null and classify_!= ''and classify_== '3'">
AND sys_user.name_ like CONCAT('%',#{descript},'%')
</if>
</where>
</select>
原因:
因为Mybatis会把 'XXX' 解析为字符,java为强类型语言,所以不能这样写.