当我遇到了字符串等值判断的时候,坑来了

问题描述:

错误代码镇楼:

<choose>
<when test="pictureDTO.isFree = '是' ">
1,
</when>
<otherwise>
0,
</otherwise>
</choose>
首先,test表达式的等值判断使用"==",弱智的我原以为会和Mysql一样用"=",然后insert的时候,字段赋值出现问题。

改正代码一:

<choose>
<when test="pictureDTO.isFree == '是' ">
1,
</when>
<otherwise>
0,
</otherwise>
</choose>
其次,字符串的判断,要用''里面套"",的方式,因为Mybatis是使用OGNL表达式来进行解析的。

改正代码二:【正确代码】

<choose>
<when test='pictureDTO.isFree == "是" '>
1,
</when>
<otherwise>
0,
</otherwise>
</choose>

错误 <if test="status == '1'">

正确 <if test="status == '1'.toString()">

转载于:https://www.cnblogs.com/wdw31210/p/9395898.html

原文地址:https://www.cnblogs.com/maohuidong/p/12143324.html