使用MyBatis Plus自动处理创建时间和最后修改时间
1.创建类
@Component public class TimeMetaObjectHandler implements MetaObjectHandler { public static final String FIELD_CREATE_TIME = "gmtCreate"; public static final String FIELD_UPDATE_TIME = "gmtModified"; @Override public void insertFill(MetaObject metaObject) { LocalDateTime now = LocalDateTime.now(); this.setFieldValByName(FIELD_CREATE_TIME, now, metaObject); this.setFieldValByName(FIELD_UPDATE_TIME, now, metaObject); } @Override public void updateFill(MetaObject metaObject) { LocalDateTime now = LocalDateTime.now(); this.setFieldValByName(FIELD_UPDATE_TIME, now, metaObject); } }