package com.nokia.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * myBatisPlus的自动填充功能实现
 *
 * @TableField(fill = FieldFill.INSERT)
 * private Date createTime;
 * @TableField(fill = FieldFill.INSERT_UPDATE)
 * private Date updateTime;
 */

@Component
public class FillMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date now = new Date();
        this.fillStrategy(metaObject, "createTime", now);
        this.fillStrategy(metaObject, "updateTime", now);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, "updateTime", new Date());
    }
}
