public class MyMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { if(metaObject.hasSetter("createTime")){ this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now()); } if(metaObject.hasSetter("createAccountId")){ Object account = RequestContextHolder.getRequestAttributes() .getAttribute("account", RequestAttributes.SCOPE_SESSION); if(account != null){ Long accountId = ((Account)account).getAccountId(); this.strictInsertFill(metaObject,"createAccountId",Long.class,accountId); } } } @Override public void updateFill(MetaObject metaObject) { if(metaObject.hasSetter("modifiedTime")){ this.strictUpdateFill(metaObject,"modifiedTime", LocalDateTime.class,LocalDateTime.now()); } if(metaObject.hasSetter("modifiedAccountId")){ Object account = RequestContextHolder.getRequestAttributes() .getAttribute("account", RequestAttributes.SCOPE_SESSION); if(account != null){ Long accountId = ((Account)account).getAccountId(); this.strictUpdateFill(metaObject,"modifiedAccountId",Long.class,accountId); } } } }
建议检查一下 BaseEntity
@TableField 注解 是UPDATE还是INSERT
少了注解
@Component 没有注入容器