zoukankan      html  css  js  c++  java
  • 【Problems】Could not set property 'id' of 'xxx' with value '' Cause argument type mismatch

    一个问题:向comment表添加记录时,报错, 无法设置值。

    reflection.ReflectionException: Could not set property 'id' of 'class com.awen.entity.Comment' with value '1246084348583632898' Cause: java.lang.IllegalArgumentException: argument type mismatch

    我的comment表中设计的id为char(19),字符类型。而我对应的实体类ProductLike中id

    设置的也是字符类型, 那是什么错误呢?

    @ApiModelProperty(value = "评论id")
    @TableId(value = "id", type = IdType.ID_WORKER)
    private String id;
    

    但我加了@TableId(value = "id", type = IdType.ID_WORKER),错误了。

    ID_WORKER是全局唯一ID (UUID) ,而我的是字符串要字符串全局唯一ID ,那就是ID_WORKER_STR。 改为ID_WORKER_STR吧 ,可以跑了。

     @ApiModelProperty(value = "评论id")
     @TableId(value = "id", type = IdType.ID_WORKER_STR)
     private String id;
    

    还有其他就是 Long id , Integer id问题。

    记录:

    @Getter
        public enum IdType {
    
            /**
             * 数据库ID自增
             */
            AUTO(0),
    
            /**
             * 该类型为未设置主键类型
             */
            NONE(1),
            /**
             * 用户输入ID
             * 该类型可以通过自己注册自动填充插件进行填充
             */
            INPUT(2),
            /* 以下3种类型、只有当插入对象ID 为空,才自动填充。 */
            /**
             * 全局唯一ID (idWorker)
             */
            ID_WORKER(3),
            /**
             * 全局唯一ID (UUID)
             */
            UUID(4),
            /**
             * 字符串全局唯一ID (idWorker 的字符串表示)
             */
            ID_WORKER_STR(5);
            private int key;
    
            IdType(int key) {
                this.key = key;
    
            }
        }
    

    UUID 通用唯一识别码

    MyBatis-Plus

    ID_WORKER

    MyBatis-Plus默认的主键策略是:ID_WORKER *全局唯一ID *

    自增策略

    要想主键自增也可以

    创建数据库的时候可以设计主键自增 ,比如idint(11) NOT NULL AUTO_INCREMENT COMMENT '用户id'

    实体字段中配置@TableId(type = IdType.AUTO)

    @TableId(type = IdType.AUTO)
    private Long id;
    

    Long

    要想影响所有实体的配置,可以设置全局主键配置

    #全局设置主键生成策略
    mybatis-plus.global-config.db-config.id-type=auto
    

    自动填充

    一些数据相同的填充,如创建时间,更新时间

    @Data
    ublic class User implements Serializable {
    	//自动填充
        @TableField(fill = FieldFill.INSERT)
        @ApiModelProperty(value = "创建时间")
        private Date createTime;
    
        @TableField(fill = FieldFill.INSERT_UPDATE)
        @ApiModelProperty(value = "更新时间")
        private Date updateTime;
    }
    
  • 相关阅读:
    Eclipse快捷键大全(转载)
    IE9浏览Flash页面时显示错位并不停地闪烁
    flash全屏事件和键盘按下事件部分不能触发问题
    AS3摘要(转载)
    【as3手册小记】ActionScript 中处理全屏模式的注意事项
    巧用FlashPaper 让Word文档变Flash
    AS3视频照相截图(转载)
    Json串到json对象的转换
    映射文件详解(转)
    Jquery .ajax方法分析(一)
  • 原文地址:https://www.cnblogs.com/liuawen/p/12854039.html
Copyright © 2011-2022 走看看