package com.xjs.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;

/**
 * mp字段自动填充处理器
 * @author xiejs
 * @since  2021-12-27
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //log.info("start insert fill ....");
        //this.setFieldValByName("createTime", new Date(), metaObject);
        this.strictInsertFill(metaObject, "createTime", Date.class,new Date()); // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "updateTime", Date.class,new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        //this.strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class); // 起始版本 3.3.3(推荐)
        this.strictInsertFill(metaObject, "updateTime", Date.class,new Date()); // 起始版本 3.3.3(推荐)
    }
    }
