你使用Ibator吗? 我项目里头是这样的: <resultMap class="model.Budget" id="ibatorgenerated_BaseResultMap"> …… <result column="mdate" jdbcType="TIMESTAMP" property="mdate" /> </resultMap>POJO: public Date getMdate() { return mdate; } /** * This method was generated by Apache iBATIS ibator. This method sets the value of the database column budget.mdate * @param mdate the value for budget.mdate * @ibatorgenerated Thu Sep 30 10:08:02 CST 2010 */ public void setMdate(Date mdate) { this.mdate = mdate; }
一个是你的sql查询或者写入对应的日期类型 date和datetime
对应的是Java的日期类型 ,多试验几个。
2、可以尝试使用字符创日期格式 sql语句通过转换函数 比如todate()来处理日期入库;
我项目里头是这样的:
<resultMap class="model.Budget" id="ibatorgenerated_BaseResultMap">
……
<result column="mdate" jdbcType="TIMESTAMP" property="mdate" />
</resultMap>POJO: public Date getMdate() {
return mdate;
}
/**
* This method was generated by Apache iBATIS ibator. This method sets the value of the database column budget.mdate
* @param mdate the value for budget.mdate
* @ibatorgenerated Thu Sep 30 10:08:02 CST 2010
*/
public void setMdate(Date mdate) {
this.mdate = mdate;
}
<resultMap>
<result column="cometime" jdbcType="DATE" property="cometime" />
<result column="gotime" jdbcType="DATE" property="gotime" />
</resultMap>在POJO中,我经常使用String来代替Date:
private String cometime;
public String getCometime() {
return cometime;
}
public void setCometime(String cometime2) {
this.cometime = cometime2;
}
但我记得,使用Date也是可行的
DAO与Domain的映射是用的Date原来是int类型为null导致resultMapping错误.加上jdbcType="int" nullValue="0"/>
就好了...
谢谢各位!
先把Date换成VarChar(20),赶项目...呵呵