mybatis动态sql将字符串转换成数字类型报错

报错信息

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
	### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "xxx"
	### Cause: java.lang.NumberFormatException: For input string: "xxx"
	java.util.concurrent.CompletionException: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 

解决办法

  • 1、外面使用单引号,参数使用双引号
<if test='test == "xxx" '>

</if>

注意!!!:当有多个判断时,需要全部使用单引号,如:

<choose>
	<when test='status == "jj"'>
      and STATUS = 'jj'
	</when>
	<when test='status == "xx"'>
      and STATUS = 'xx'
	</when>
	<otherwise>
		and STATUS != 'jj' and STATUS != 'xx'
	</otherwise>
</choose>

  • 2、加toString()方法
<if test="test == 'xxx'.toString()">

</if>
posted @   fchhk  阅读(394)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 我与微信审核的“相爱相杀”看个人小程序副业
· DeepSeek “源神”启动!「GitHub 热点速览」
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示