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>
偶做前堂客
祝你天天开心
在未知的时间
在未知的地点