天天看點

mybatis java.lang.NumberFormatException: For input string: "y"

今天在做mybatis的查詢時,報了一個奇葩錯:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "y"
### Cause: java.lang.NumberFormatException: For input string: "y"
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
	at com.sun.proxy.$Proxy219.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128)
           

引起異常的代碼如下:

<if test="like == 'y'">
    AND o.short_code LIKE CONCAT('%', #{shortCode}, '%')
</if>
           

經過網上查找,原來’y’被認為是char類型,'yy’或者“y”沒有問題。

如何解決?

  1. 将代碼改為 test=“like == ‘y’.toString()”
  2. 将代碼改為 test=“like == “y””
  3. 将代碼改為 test=‘like == “y”’