MybatisPlus使用@TableId主鍵id自增長(zhǎng)無效的解決
問題情況:
在使用 @TableId(type = IdType.AUTO)之后添加的id數(shù)字特別大
原因:
因?yàn)樵诘谝淮问褂玫臅r(shí)候沒有加注解 所以mybatis自動(dòng)生成了一個(gè)特別大的數(shù)字
當(dāng)我們第二次加上注解之后他的id實(shí)際上還是第一次那個(gè)特別大的數(shù)字+1
解決方法
修改表的自動(dòng)添加值再添加
因?yàn)榈谝淮翁砑拥膇d值特別大我就把那一行給刪了
然后改了自增長(zhǎng)的數(shù)字
如圖所示
修改之后就好了
package com.tong.pojo; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor @TableName("tb_user") public class User { @TableId(type = IdType.AUTO) //指定id類型為自增長(zhǎng) private Long id; private String user_name; private String password; private String name; private Integer age; private String email; }
package org.example; import com.tong.MyApplication; import com.tong.mapper.UserMapper; import com.tong.pojo.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes= MyApplication.class) public class TestUserMapper { @Autowired private UserMapper userMapper; 上面這一行報(bào)錯(cuò)是正?,F(xiàn)象 @Test public void test(){ User user = new User(); user.setEmail("12345.com"); user.setAge(20); user.setUser_name("caocao1"); user.setName("曹操1"); user.setPassword("123456"); //user.setAddress("北京"); int insert = userMapper.insert(user); System.out.println(insert); System.out.println(user.getId()); } }
到此這篇關(guān)于MybatisPlus使用@TableId主鍵id自增長(zhǎng)無效的解決的文章就介紹到這了,更多相關(guān)MybatisPlus @TableId主鍵id自增長(zhǎng)無效內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決 java.lang.NoSuchMethodError的錯(cuò)誤
這篇文章主要介紹了解決 java.lang.NoSuchMethodError的錯(cuò)誤的相關(guān)資料,需要的朋友可以參考下2017-06-06java集合框架的體系結(jié)構(gòu)詳細(xì)說明
最近在一本J2EE的書中看到了很不錯(cuò)的對(duì)集合框架的說明文章2012-11-11swagger2隱藏在API文檔顯示某些參數(shù)的操作
這篇文章主要介紹了swagger2隱藏在API文檔顯示某些參數(shù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06Java Jackson之ObjectMapper常用用法總結(jié)
這篇文章主要給大家介紹了關(guān)于Java Jackson之ObjectMapper常用用法的相關(guān)資料,ObjectMapper是一個(gè)Java庫(kù),用于將JSON字符串轉(zhuǎn)換為Java對(duì)象或?qū)ava對(duì)象轉(zhuǎn)換為JSON字符串,需要的朋友可以參考下2024-01-01詳解SpringBoot中Session超時(shí)原理說明
本篇文章主要介紹了詳解SpringBoot中Session超時(shí)原理說明,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08淺談 java中ArrayList、Vector、LinkedList的區(qū)別聯(lián)系
ArrayList,Vector底層是由數(shù)組實(shí)現(xiàn),LinkedList底層是由雙線鏈表實(shí)現(xiàn),從底層的實(shí)現(xiàn)可以得出性能問題ArrayList,Vector插入速度較慢,查詢速度較快,而LinkedList插入速度較快,而查詢速度較慢。再者由于Vevtor使用了線程安全鎖,所以ArrayList的運(yùn)行效率高于Vector2015-11-11java實(shí)現(xiàn)字符串四則運(yùn)算公式解析工具類的方法
今天小編就為大家分享一篇java實(shí)現(xiàn)字符串四則運(yùn)算公式解析工具類的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07springMvc注解之@ResponseBody和@RequestBody詳解
本篇文章主要介紹了springMvc注解之@ResponseBody和@RequestBody詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05Myeclipse鏈接Oracle等數(shù)據(jù)庫(kù)時(shí)lo exception: The Network Adapter coul
今天小編就為大家分享一篇關(guān)于Myeclipse鏈接Oracle等數(shù)據(jù)庫(kù)時(shí)lo exception: The Network Adapter could not establish the connection,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03