1、使用中出现的问题
XxxxMapper.xml
<if test="code !=null and code == 'a' " >
//此处省略...
</if>
异常
### Error querying database. Cause: java.lang.NumberFormatException: For input string: "a"
### Cause: java.lang.NumberFormatException: For input string: "a"
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy97.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
说明: a
明明的字符串,使用单引号,为什么mybatis 要对把它当作 数字 来使用呢?
2、解决方法:
方法1、加上 ‘a’.toString()
<if test="code != null and code == 'a'.toString() " >
//此处省略...
</if>
方法2、里面的单引号使用转义符号 "
<if test="code != null and code == "a" " >
//此处省略...
</if>
方法3、外面是单引号,里面使用双引号
<if test='code != null and code == "a" ' >
//此处省略...
</if>
3、
TODO 没写完