MyMetaObjectHandler.java
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.huaheng.framework.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.huaheng.common.utils.security.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* Created by Enzo Cotter on 2020/7/7.
*/
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler{
/**
* 插入元对象字段填充(用于插入时对公共字段的填充)
*
* @param metaObject 元对象
*/
@Override
public void insertFill(MetaObject metaObject) {
log.info("start insert fill ....");
this.setFieldValByName("created", new Date(), metaObject);
this.setFieldValByName("createdBy", ShiroUtils.getLoginName(), metaObject);
this.setFieldValByName("lastUpdated", new Date(), metaObject);
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getLoginName(), metaObject);
}
/**
* 更新元对象字段填充(用于更新时对公共字段的填充)
*
* @param metaObject 元对象
*/
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("lastUpdated", new Date(), metaObject);
this.setFieldValByName("lastUpdatedBy", ShiroUtils.getLoginName(), metaObject);
}
}