映射器文件 employeeMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxxx.sample.test.dao.TestDAO">
<select id="selectEmployee" parameterType="int" resultMap="com.viasat.sample.domain.CreateDate" >
select createdate from employee where id = #{id}
</select>
</mapper>
映射器接口 TestDAO.java
public interface TestDAO {
public com.viasat.sample.domain.CreateDate selectEmployee(int id);
}
POJO Bean CreateDate.java
public class CreateDate {
private XMLGregorianCalendar createdate;
public XMLGregorianCalendar getCreatedate() {
return createdate;
}
public void setCreatedate(XMLGregorianCalendar createdate) {
this.createdate = createdate;
}
}
主要方法 MainClass.java
public class MainClass {
public static void main(String[] args) {
SqlSession session = sqlSessionFactory.openSession();
try {
TestDAO tm = session.getMapper(TestDAO.class);
Map emp = tm.selectEmployee(123);
} catch (Exception e) {
e.printStackTrace();
}
finally {
session.close();
}
}
}
问题:从中检索的日期值(createdate)未映射/设置为 CreateDate bean 中的 XMLGregorianCalendar 类型 createdate。如果 createdate 的数据类型是 Date,它工作正常。简而言之,Mybatis 的 XMLGregorianCalendar 类型中没有设置 DATE 数据类型。