mybatis 的 if、test 表达式中单引号与双引号的区别
1、使用中出现的问题XxxxMapper.xml<if test="code !=null and code == 'a' " >//此处省略...</if>异常### Error querying database.Cause: java.lang.NumberFormatException: For input string: "a"### Cause: java.la
·
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 没写完

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)