com.midcu.common.component.BaseMetaObjectHandler Maven / Gradle / Ivy
The newest version!
package com.midcu.common.component;
import cn.dev33.satoken.stp.StpUtil;
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.time.LocalDateTime;
@Slf4j
@Component
public class BaseMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class); // 起始版本 3.3.3(推荐)
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); // 起始版本 3.3.3(推荐)
if (StpUtil.isLogin()) {
this.strictUpdateFill(metaObject, "updateUser", StpUtil::getLoginIdAsString, String.class); // 起始版本 3.3.3(推荐)
this.strictInsertFill(metaObject, "createUser", StpUtil::getLoginIdAsString, String.class); // 起始版本 3.3.3(推荐)
}
}
@Override
public void updateFill(MetaObject metaObject) {
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); // 起始版本 3.3.3(推荐)
if (StpUtil.isLogin()) {
this.strictUpdateFill(metaObject, "updateUser", StpUtil::getLoginIdAsString, String.class); // 起始版本 3.3.3(推荐)
}
}
}