mybatis中判断字符串

来源:互联网 发布:luaeditor mac 编辑:程序博客网 时间:2024/06/03 13:25

mapper.xml中判断字符串

<if test="flag == 'N'">

AND cust.certificate_no NOT IN (#{idCards})

</if>

这种写法会报:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "N"
### Cause: java.lang.NumberFormatException: For input string: "N"


因为mybatis映射文件,是使用的ognl表达式,所以会把‘Y'解析为char,java是强类型的语言,不能这样写,正确写法:

<if test="flag == 'N'.toString()">

AND cust.certificate_no NOT IN (#{idCards})

</if>

或者

<if test='flag == "N"'>

AND cust.certificate_no NOT IN (#{idCards})

</if>