preface

I want to use LocalDateTime, and I don’t want to change the previous code

Train of thought

Start directly with MetaObject

    @Override
    public void insertFill(MetaObject metaObject) { Object createTimeField; Object updateTimeField; Class<? > createTimeType; Class<? > updateTimeType; createTimeField =this.getFieldValByName("createTime", metaObject);
        updateTimeField = this.getFieldValByName("updateTime", metaObject);

        createTimeType = metaObject.getGetterType("createTime");
        updateTimeType = metaObject.getGetterType("updateTime");

        if (isNull(createTimeField)) {
            if (createTimeType.equals(Date.class)) {
                this.strictInsertFill(metaObject,"createTime", Date::new,Date.class);
            } else if (createTimeType.equals(LocalDateTime.class)){
                this.strictInsertFill(metaObject,"createTime", LocalDateTime::now,LocalDateTime.class); }}if (isNull(updateTimeField)){
            if (updateTimeType.equals(Date.class)) {
                this.strictInsertFill(metaObject,"updateTime", Date::new,Date.class);
            } else if (updateTimeType.equals(LocalDateTime.class)){
                this.strictInsertFill(metaObject,"updateTime", LocalDateTime::now,LocalDateTime.class); }}this.setFieldValByName("deleted".0, metaObject);
    }
Copy the code

Use the metaObject.getgetterType () method to get the type of the field

At the end

The content of this article is not much, I hope to provide a method for students who also encounter this situation later