夺笋2562325
2022-05-01 19:26
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 没有注入容器
MyBatis-Plus + SpringBoot实现简单权限管理
12724 学习 · 133 问题
相似问题