现象

项目启动时出现<This primary key of "id" is primitive !不建议如此请使用包装类 in Class:xxx>异常。

WARN 22232 --- [           main] c.b.m.core.metadata.TableInfoHelper      : This primary key of "id" is primitive !不建议如此请使用包装类 in Class: "com.lizz.po.UserPO"

原因

mybatis-plush框架对数据类型进行判断

 Class<?> keyType = tableInfo.getReflector().getGetterType(property);
            if (keyType.isPrimitive()) {
                logger.warn(String.format("This primary key of \"%s\" is primitive !不建议如此请使用包装类 in Class: \"%s\"", property, tableInfo.getEntityType().getName()));
            }

keyType.isPrimitive(),当对象主键类型是原始类型时,报出错误提示。

解决方案

将对象中的主键改为非原始类型即可。

如:

@Data
public class UserPO {
    @TableId(value = "id", type = IdType.AUTO)
    private int id;
    private String userId;
}

改为:

@Data
public class UserPO {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private String userId;
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐