添加一个字段
实体类标注填充的字段
@TableField(fill = FieldFill.INSERT) private Date createTime;
配置自动自动填充类MyMetaObjectHandler
@Component public class MyMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { this.setFieldValByName("createTime",new Date(),metaObject); } @Override public void updateFill(MetaObject metaObject) { } }
测试
@Test void testInsert(){ User user = new User(); user.setName("小赵"); user.setAge(18); user.setEmail("2676580540@qq.com"); userMapper.insert(user); }
实现效果