package com.risesun.business.hander;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.risesun.common.security.utils.SecurityUtils;
import java.util.Date;
/**
* @Author LiXiangrong
* @Description 兼容MybatisPlus自动填充字段值
* @Date 2023/06/01 14:33:37
**/
@Component
public class MybatisPlusHandler implements MetaObjectHandler
{
public static final Logger LOGGER = LoggerFactory.getLogger(MybatisPlusHandler.class);
@Override
public void insertFill(MetaObject metaObject)
{
LOGGER.info("MybatisPlusHandler开始自动填充创建时间、创建人属性值...");
this.setFieldValByName("createBy", SecurityUtils.getUsername(),metaObject);
this.setFieldValByName("createTime",new Date(),metaObject);
}
@Override
public void updateFill(MetaObject metaObject)
{
LOGGER.info("MybatisPlusHandler开始自动填充更新时间、更新人属性值...");
this.setFieldValByName("updateBy",SecurityUtils.getUsername(),metaObject);
this.setFieldValByName("updateTime",new Date(),metaObject);
}
}
版权属于:
lixiangrong
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)