@TableId(type = IdType.AUTO)该注解用于数据库设定了主键自增
@TableId(type = IdType.ASSIGN_ID)该注解需要给主键手动传值
在使用mybatisplus时,主键报错,提示主键为空,原因是前端手动传了一个id主键,错用了@TableId(type = IdType.AUTO),如果没有在数据库设定主键自增,且没有添加@TableId(type = IdType.AUTO),会报错
Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value ; Field ‘id‘ doesn‘t have
最新推荐文章于 2023-07-28 16:35:22 发布
博客介绍了MyBatisPlus中@TableId注解的使用,@TableId(type = IdType.AUTO)用于数据库主键自增,@TableId(type = IdType.ASSIGN_ID)需手动传主键值。还指出使用时主键报错为空的原因,如前端手动传id却错用自增注解,未设自增且未添加注解也会报错。
2093

被折叠的 条评论
为什么被折叠?



