mybatisplus 添加 /修改 数据 插入公共字段

@TableField(value = "CREATED_BY", fill = FieldFill.INSERT)
private String createdBy;
@TableField(value = "CREATED_TIME", fill = FieldFill.INSERT)
private Date createdTime;
@TableField(value = "UPDATED_BY", fill = FieldFill.UPDATE)
private String updatedBy;
@TableField(value = "UPDATED_TIME", fill = FieldFill.UPDATE)
private Date updatedTime;


/**
* 自动填充功能
* @return
*/
@Bean
public GlobalConfig globalConfig() {
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setMetaObjectHandler(new MetaHandler());
return globalConfig;
}



import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.vimtech.common.util.ShiroUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
* @Date 2020-02-24 09:57
* @Author sulg
* @Description 公共字段填充
*/
@Component
public class MetaHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("createdBy", ShiroUtils.getUserName(), metaObject);
this.setFieldValByName("createdTime", new Date(), metaObject);
}

@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("updatedBy", ShiroUtils.getUserName(), metaObject);
this.setFieldValByName("updatedTime", new Date(), metaObject);
}
}
上一篇:sqlQuery.list()方法返回类型


下一篇:使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”