mybatis xml 参数numberformatException

来源:互联网 发布:海报模板网站 知乎 编辑:程序博客网 时间:2024/06/04 18:51
错误描述
<select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"> select * from treatment where TRUE <if test="index == 'A'"> AND ensubject IS NOT NULL AND ensubject <> '' </if> </select>

 

当使用的index为A时,这段便抛出一个NumberFormatExeption的异常,但是如果index为一个数值比如1时就运行正常。

 

解决方案:

1.改为:test="param eq 'A'.toString()"
2.原因是mybatis标签语法的问题:
这里 'A' 将被认为是 char 类型,但是 'AA' 或者 "A" 将被作为 String类型。

所以我们可以用转义:<if test="name == &quot;A&quot;">
3.或者将 <if test="index == 'A'"> 改为 <if test='index == "A"'>。


 

0 0