添加了实体类字段自动填充类
parent
784e8aad01
commit
a608cbea81
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.common.datascope;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: MyMetaObjectHandler
|
||||
* @Description: 实体类字段自动填充
|
||||
* @CreatedDate: 2024/8/8 下午5:16
|
||||
* @FilePath: com.muyu.common.datascope
|
||||
*/
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: MyMetaObjectHandler
|
||||
* @Description: 实体类字段自动填充
|
||||
* @CreatedDate: 2024/8/8 下午5:16
|
||||
* @FilePath: com.muyu.common.datascope
|
||||
*/
|
||||
@Component
|
||||
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
/**
|
||||
* 插入时触发
|
||||
* @param metaObject
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
// 创建人
|
||||
this.setFieldValByName("createBy", SecurityUtils.getUserId(), metaObject);
|
||||
// 创建时间
|
||||
this.setFieldValByName("createTime", new Date(), metaObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新时触发
|
||||
* @param metaObject
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
// 更新人
|
||||
this.setFieldValByName("updateBy", SecurityUtils.getUserId(), metaObject);
|
||||
// 更新时间
|
||||
this.setFieldValByName("updateTime", new Date(), metaObject);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue