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>
本文介绍了在MyBatis的mapper.xml文件中如何正确地进行字符串条件判断,避免因类型不匹配导致的NumberFormatException错误,并提供了两种正确的实现方式。
8万+

被折叠的 条评论
为什么被折叠?



