一、TbaleMetaObjectHandler
package com.ybzx.zdbx.common.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
@Slf4j
public class TbaleMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
//判断当前对象的自动填充属性是否包含当前属性
if (metaObject.hasSetter("ENTERDATE")) {
//实现填充业务逻辑
Date now = new Date();
this.strictInsertFill(metaObject, "ENTERDATE", Date.class, now);
this.strictInsertFill(metaObject, "MODITM", Date.class, now);
}
}
@Override
public void updateFill(MetaObject metaObject) {
if (metaObject.hasSetter("MODITM")) {
//实现填充业务逻辑
this.strictUpdateFill(metaObject, "MODITM", Date.class, new Date());
}
}
}
二、属性
每次新增,识别到实体类具有对应的属性就会触发方法填充日期