我是靠谱客的博主 阔达大叔,这篇文章主要介绍mybatis中判断字符串,现在分享给大家,希望可以做个参考。

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中判断字符串的全部内容,更多相关mybatis中判断字符串内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部