mybatis中使用if标签比较两个字符串是否相等

今日一坑
转自:http://www.cnblogs.com/a8457013/p/8033549.html

问题:

mybatis中,if标签,when标签中都会有条件判断:test;如何判断两个字符串是否相等

解决:

<if test="dy != null and dy != ''">
	<if test="kskm != null and kskm != ''">
		<choose>
			<when test='dy == "1"'>and upper(a.aa) = upper(#{kskm, jdbcType=VARCHAR})</when>
			<!-- 或者 -->
			<when test="dy == '1'.toString()">and upper(a.aa) = upper(#{kskm, jdbcType=VARCHAR})</when>
		</choose>
	</if>
</if>

不能使用:

<when test="dy == '1'">and upper(a.aa) = upper(#{kskm, jdbcType=VARCHAR})</when>

解释:

因为mybatis会把’Y’解析为字符,java是强类型语言,所以不能这样写。

猜你喜欢

转载自blog.csdn.net/shelly_Chestnut/article/details/84858927