Mybatis insert java.util.Date into the mysql datetime column, then select it if they don't match.
Table
CREATE TABLE `t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `create_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
code
@Insert("insert into t(create_time) values(#{0})") int insertT(Date date); @Select("select create_time from t order by id desc limit 1") Date getLatestCreateTime();
Unit test
Date date1 = new Date(); mapper.insertT(date1); Date date2 = mapper.getLatestCreateTime(); Assert.assertEquals(date1, date2);
Confirmation Error
java.lang.AssertionError: Expected :Tue Aug 02 22:10:35 CST 2016 Actual :Tue Aug 02 22:10:36 CST 2016
why is that?
source share