【发布时间】:2019-08-22 09:13:58
【问题描述】:
我刚接触 Spring,对iBatis 有点困惑。我的任务是编辑选择查询条件(非常简单),但事情变得棘手。
我只将java.sql.Date 对象(带有setter 和getter)传递给SQLMapper 以提供条件参数。
这就是我的WHERE 子句的样子
<sql id="dateWhere">
<where>
<if test="arg.sqlStartDate != null and arg.sqlEndDate != null">
table.date BETWEEN #{arg.sqlStartDate} AND #{arg.sqlEndDate}
</if>
</where>
</sql>
但我得到一个错误
org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='arg.sqlStartDate', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException
我研究了我需要指定参数的jdbcType。 SOlink。还添加了DATE() 函数以进一步指定参数是DATE 变量。
<sql id="dateWhere">
<where>
<if test="arg.sqlStartDate != null and arg.sqlEndDate != null">
table.date BETWEEN DATE(#{arg.sqlStartDate,jdbcType=DATE}) AND DATE(#{arg.sqlEndDate,jdbcType=DATE})
</if>
</where>
</sql>
我让它工作了。但我注意到其他 Mapper 他们没有指定每个参数的jdbcType。所以我对这个问题到底是什么以及导致它的原因感到困惑,这是如何发生的,我做错了什么。只需给我信息以进一步了解这件事。谢谢
【问题讨论】: