记录一下因mybatis-plus版本不一致导致的实体主键id未赋值,新增失败问题

发布时间 2023-04-20 11:03:40作者: 一曲终两人遇

记录一下因mybatis-plus版本不一致导致的实体主键id未赋值,新增失败问题
mybatis-plus中对于id的赋值在
package com.baomidou.mybatisplus.core;
public class MybatisParameterHandler implements ParameterHandler {} 中实现
1)3.4.1版本中的实现如下,处理 IdType.ASSIGN_ID 和 IdType.ASSIGN_UUID

2)3.2.0版本中的实现如下,
package com.baomidou.mybatisplus.core;
public class MybatisDefaultParameterHandler extends DefaultParameterHandler {}

问题出现场景:位于公司后台管理系统中(项目依赖非本人搭建),因同事平时设置的数据库主键自增,id采用int类型,type=IdType.AUTO,所以未出现此问题
@ApiModelProperty("主键ID") @TableId(type = IdType.ASSIGN_ID) private Long id;
@TableId是mybatis-plus-annotation依赖中的注解,项目中使用的是3.4.0版本;说明(3.2.0的版本是没有用IdType.ASSIGN_ID的)
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-annotation</artifactId> <version>3.4.0</version> </dependency>
而mybatis-plus使用的是3.2.0的版本
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency>
从3.2.0的MybatisDefaultParameterHandler 方法来看,是没有对type = IdType.ASSIGN_ID的处理,所以id没有被赋值。
我将依赖都修改成3.4.0,问题解决