问答详情
源自:7-4 客户管理自动填充功能

老师,您好,请问一下创建时间和修改时间有效,创建人和修改人取不到,是因为从session中没取到account对象吗?

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);
            }
        }
    }
}


提问者:夺笋2562325 2022-05-01 19:26

个回答

  • qq_来自地球的我_0
    2023-01-07 00:57:05

    建议检查一下  BaseEntity

    @TableField  注解   是UPDATE还是INSERT

  • BIgdecSun
    2022-11-22 18:32:57

    少了注解

    @Component  没有注入容器

    http://img2.mukewang.com/637ca52e00015f2809850297.jpg