smartleizi 2011-04-29
pojo类设计为Date类型,MySQL数据库的表字段为datetime,就是
Useru=newUser();
u.setCreateDate(此处为Date类型);
1.修改User.hbm.xml
<propertyname="createdDate"type="date">
<columnname="CREATED_DATE"length="7"not-null="true"/>
</property>
为
<propertyname="createdDate"column="CREATED_DATE">
</property>
2.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d = new Date(); u.setCreateDate(sdf.parse(sdf.format(d)));