mybatis-generator生成的xml对日期处理存在问题.
下面的代码用于向数据库中添加排班信息
public int addWatcherInfo(Watcher watcher) { int insert = watcherMapper.insert(watcher); log.info("添加排班信息执行完毕,返回值是:" + insert); return insert; } |
watcher信息如下
Watcher{id=null, date=Wed Aug 29 00:00:00 GMT+08:00 2018, startTime=Wed Aug 29 01:00:00 GMT+08:00 2018, endTime=Wed Aug 29 02:00:00 GMT+08:00 2018, watcher='李通', phone='13121933622'} |
但是执行的sql语句如下
==> Preparing: insert into watcher (id, date, start_time, end_time, watcher, phone ) values (?, ?, ?, ?, ?, ? ) ==> Parameters: null, 2018-08-29(Date), 2018-08-29(Date), 2018-08-29(Date), 李通(String), 13121933622(String) |
为什么start_time和end_time的时分秒会没有呢
一探究竟
在mapper.xml中内容如下
<insert id="insert" parameterType="com.hg.gxdw.watch_info.model.Watcher"> insert into watcher (id, date, start_time, end_time, watcher, phone) values (#{id,jdbcType=INTEGER}, #{date,jdbcType=DATE}, #{startTime,jdbcType=DATE}, #{endTime,jdbcType=DATE}, #{watcher,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}) </insert> |
jdbcType指定数据中的数据类型,mysql数据中和日期相关的有下面三种类型
1)DATETIME
显示格式:YYYY-MM-DD HH:MM:SS
时间范围:[ '1000-01-01 00:00:00'到'9999-12-31 23:59:59']
2)DATE
显示格式:YYYY-MM-DD
时间范围:['1000-01-01'到'9999-12-31']
3)TIMESTAMP
显示格式:YYYY-MM-DD HH:MM:SS
时间范围:[ '1970-01-01 00:00:00'到'2037-12-31 23:59:59']