baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.42k stars 4.31k forks source link

[错误报告]: 描述 自动填充功能 LocalDateTime类型可以填充 Long类型无法填充 #6588

Closed tongtian100 closed 2 hours ago

tongtian100 commented 3 hours ago

确认

当前程序版本

3.5.9

问题描述

LocalDateTime类型可以填充 Long类型无法填充 bug示例:https://github.com/tongtian100/my-bug 代码

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
      //  log.info("开始插入填充...");
        this.strictInsertFill(metaObject, "createdTime", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "updatedTime", LocalDateTime.class, LocalDateTime.now());
      //无法填充
        this.strictUpdateFill(metaObject, "createdBy", Long.class, 1L);
    }

实体类

@Data
@Accessors(chain = true)
public class BaseEntity implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdTime;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedTime;
    private LocalDateTime deletedTime;
    @TableLogic
    private Boolean deleted;
    @TableField(fill = FieldFill.INSERT)
    private Long createdBy;
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updatedBy;
    @Version
    private Long version;
}

user实体类

@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@TableName("user")
public class UserEntity extends BaseEntity {
    private String username;
    private String passwordHash;
    private String email;
    private String firstName;
    private String lastName;
    private String phoneNumber;
    private LocalDate dateOfBirth;
    private String gender;
    private String address;
    private String city;
    private String state;
    private String country;
    private String postalCode;
    private LocalDateTime lastLogin;
    private Boolean isActive;
    private Boolean isStaff;
    private String profilePicture;
}

详细堆栈日志

No response

miemieYaho commented 2 hours ago

update不在insert时填充