Skip to content

错误描述

将projectGrade与"大"进行比较,xml如下所示:

xml
<when test="projectGrade == '大'">
       AND project_grade in ('Ⅰ','Ⅱ')
</when>

报错信息:

java
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "大"
### Cause: java.lang.NumberFormatException: For input string: "大"] with root cause

出错原因

这是由于mybatis参数格式化异常导致。 解决方法

  1. 用toString()转成字符串, '大'.toString()
  2. 改为双引号"大",外层使用单引号。

改为:

java
<when test='projectGrade == "大"'>
      AND project_grade in ('Ⅰ','Ⅱ')
</when>