【发布时间】:2015-11-24 04:10:16
【问题描述】:
我在弄清楚如何使用 mybatis 从 SQL 查询中返回单个 DateTime 时遇到了一些麻烦:
我的界面的相关部分:
DateTime getMinActual(@Param("IDs") List<Integer> IDs);
我的映射器 xml 的相关部分:
<resultMap id="dtt" type="org.joda.time.DateTime">
<result column="dt" property="time" javaType="org.joda.time.DateTime" jdbcType="TIMESTAMP" typeHandler="org.joda.time.mybatis.handlers.DateTimeTypeHandler" />
</resultMap>
<select id="getMinActual" resultMap="dtt">
select min(cast(case when [quarter]=1 then '1/' when [quarter]=2 then '4/' when [quarter]=3 then '7/' else '10/' end + '1/' + cast([year] as varchar) as datetime)) as dt
from
Ops where id in
<foreach item="IDs" index="index" collection="IDs"
open="(" separator="," close=")">
#{IDs}
</foreach>
</select>
我的问题似乎与属性 = "time" 相关,因为我收到此错误:
org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'time' in 'class org.joda.time.DateTime'
我尝试了所有不同的属性名称,例如 DateTime、datetime、dateTime、org.joda.time.DateTime 等...都出现相同的错误。
有什么想法吗?
更新指出 JodaTime 是不可变的,但这应该可以工作:
<resultMap id="dtt" type="org.joda.time.DateTime">
<constructor>
<idArg column="dt" javaType="org.joda.time.DateTime" typeHandler="org.joda.time.mybatis.handlers.DateTimeTypeHandler" />
</constructor>
</resultMap>
【问题讨论】:
-
Joda 类是不可变的,它们没有设置器。
-
公平...但是我的编辑应该可以工作,但它没有。
-
您是否考虑编写自己的类型处理程序?
标签: spring-mvc jodatime mybatis spring-mybatis