报错:
### Error querying database. Cause: java.lang.NumberFormatException: For input string: "{0=null}"
### Cause: java.lang.NumberFormatException: For input string: "{0=null}"
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
... 42 more
Caused by: java.lang.NumberFormatException: For input string: "{0=null}"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at org.apache.ibatis.ognl.OgnlOps.doubleValue(OgnlOps.java:259)
at org.apache.ibatis.ognl.OgnlOps.compareWithConversion(OgnlOps.java:143)
at org.apache.ibatis.ognl.OgnlOps.isEqual(OgnlOps.java:186)
at org.apache.ibatis.ognl.OgnlOps.equal(OgnlOps.java:578)
at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:51)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:56)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45)
at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29)
at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:30)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29)
at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:47)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:265)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
解决方法:
<sql id="queryExpressCondition">
<where>
<if test="#{expressCode}!=null">
and express_code=#{expressCode}
</if>
<if test="#{expressCountry}!=null">
and express_country =#{expressCountry}
</if>
<if test="0!=#{expressStatus}">
and express_status=#{expressStatus}
</if>
<if test="0!=#{expressType}">
and express_type=#{expressType}
</if>
</where>
</sql>
代码中 expressStatus 和expressType是int类型,mybatis框架中#号为了防止sql注入,对所有的数据都加上了双引号,所以在int类型是 直接不用写#{} 或者改为 ${} 包裹即可.
如下:
<sql id="queryExpressCondition">
<where>
<if test="#{expressCode}!=null">
and express_code=#{expressCode}
</if>
<if test="#{expressCountry}!=null">
and express_country =#{expressCountry}
</if>
<if test="0!=expressStatus">
and express_status=#{expressStatus}
</if>
<if test="0!=expressType">
and express_type=#{expressType}
</if>
</where>
</sql>