一、自动填充 // create_time
(1)数据库表中添加datetime类型的字段 create_time、update_time
`create_time` datetime NOT NULL COMMENT '创建时间',
`update_time` datetime NOT NULL COMMENT '更新时间',
(2)实体类尚添加注解 @TableField
@Data
public class User {
@TableField(fill = FieldFill.INSERT)
private Date createTime;
//@TableField(fill = FieldFill.UPDATE)
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
(3)实现元对象处理器接口,handler包下
注意:不要忘记添加 @Component 注解
package com.niki.mybatisplus.handler;
import ...
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
private static final Logger LOGGER =
LoggerFactory.getLogger(MyMetaObjectHandler.class);
@Override
public void insertFill(MetaObject metaObject