当前使用版本(必填,否则不予处理)

3.5.5

该问题是如何引起的?(确定最新版也有问题再提!!!)

在最新版本中,当前端传入的主键ID为“”时 会出现报错 例如Cause: java.sql.SQLException: Incorrect integer value: '' for column 'crm_id' at row 1; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect integer value: '' for column 'crm_id' at row 1; nested exception is java.sql.SQLException: Incorrect integer value: '' for column 'crm_id' at row 1] with root cause

重现步骤(如果有就写完整)

MyBatis-Plus mybatis-plus 3.5.5主键自增问题

@Data
public class Crm implements Serializable {
    /**
     * 客户ID
     */
    @TableId(type = IdType.AUTO)
    private String crmId;

    /**
     * 客户编码
     */
    private String crmNo;

    /**
     * 简称
     */
    private String crmName;

    /**
     * 客户名称
     */
    private String fullName;

    /**
     * 目录id
     */
    private Integer dirId;

    /**
     * 联系人
     */
    private String contacts;

    /**
     * 客户联系方式
     */
    private String phone;

    /**
     * 客户地址
     */
    private String address;

    /**
     * 
     */
    private String remark;

    /**
     * 逻辑删除【01:未删除 02:删除】
     */
    private String isDelete;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 邮编
     */
    private String postCode;

    /**
     * 传真
     */
    private String fax;

    /**
     * 账户
     */
    private String bankAccount;

    /**
     * 开户行
     */
    private String bank;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}
@Data
public class CrmAo {

    private String crmId;

    /**
     * 客户编码
     */
    private String crmNo;

    /**
     * 简称
     */
    private String crmName;

    /**
     * 客户名称
     */
    private String fullName;
}
    @PostMapping("/add")
    public String insert(@RequestBody CrmAo ao){
        Crm crm = new Crm();
        BeanUtils.copyProperties(ao, crm);
        System.out.println(crm);
        int insert = crmMapper.insert(crm);
        return "插入成功" + insert;
    }

报错信息

 Cause: java.sql.SQLException: Incorrect integer value: '' for column 'crm_id' at row 1
; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect integer value: '' for column 'crm_id' at row 1; nested exception is java.sql.SQLException: Incorrect integer value: '' for column 'crm_id' at row 1] with root cause

java.sql.SQLException: Incorrect integer value: '' for column 'crm_id' at row 1

Comment From: cute050

此方式在3.3.1.tmp版本中没有问题

Comment From: KeyBoard-dot

改下你id类型为integer试试,可能是的id类型填错了(自增)

Comment From: cute050

Integer 当然是可以的 但是按道理来说 3.3.1版本是可以这么操作 3.5.5是去除这个了吗

Comment From: nieqiurong

以前自增ID的字段没有生成在insert语句之中,如果是自增的ID,最好是保持数据类型一致

Comment From: nieqiurong

用3.5.6-SNAPSHOT版本,开启下面配置试试.

mybatis-plus:
  global-config:
    db-config:
      insert-ignore-auto-increment-column: true

Comment From: cute050

谢谢回复,已解决