BaseEntity
/**
* 创建时间
*/
@TableField(fill =FieldFill.INSERT)
private Date createDate;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
@TableField(fill =FieldFill.UPDATE)
private Date updateDate;
config
package com.project.management.contractor.progress.config;
import java.util.Date;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler{
@Override
public void insertFill(MetaObject metaObject) {
// TODO Auto-generated method stub
log.info("创建时间");
this.setFieldValByName("createDate", new Date(), metaObject);
this.setFieldValByName("updateDate", new Date(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("修改时间");
this.setFieldValByName("updateDate", new Date(), metaObject);
}
}