您的位置:首页 > 其它

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

2017-12-13 16:26 573 查看
<!--此处使用if比较是否相等-->

范例一:

<selectid="findClientIds"parameterType="map"resultType="map">
SELECTsys_user.id,sys_user.clientIdFROMsys_user
<where>
<iftest="grade!=nullandgrade!=''andgrade=='3'.toString()">
id=(
SELECTPRIMARY_PERSONFROMsys_officeWHEREid=
(SELECToffice_idFROMsys_userWHEREid=#{userId}
))
</if>
<iftest="grade!=nullandgrade!=''andgrade=='2'.toString()">
id=(
SELECTPRIMARY_PERSONFROMsys_officeWHEREid=
(SELECTcompany_idFROMsys_userWHEREid=#{userId}
))
</if>
<iftest="grade!=nullandgrade!=''andgrade=='1'.toString()">
id=''
</if>
</where>
</select>


范例二:

mybatis映射文件中,if标签判断字符串相等,两种方式:
因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串sex变量是否是字符串Y的时候

<iftest="sex=='Y'.toString()">

或者使用下面的写法
<iftest='sex=="Y"'>


注意:
不能使用

<iftest="sex=='Y'">
and1=1
</if>




因为mybatis会把'Y'解析为字符,java是强类型语言,所以不能这样写。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: