Mapper.xml主鍵自增


https://www.cnblo在 mapper.xml 中對於的數據庫的表中,由於表設計的是主鍵自增,所以添加的時候不用給主鍵 id 賦值,數據庫會自動的給 id 賦值,而怎么拿到賦值后的 id 呢,需要在 mapper.xml 中的 insert 中加入:
  useGeneratedKeys="true" keyProperty="id" //得到 id
如:
<insert id="insertSelective" parameterType="com.miaoshaproject.dataproject.UserDo" useGeneratedKeys="true" keyProperty="id">
  Insert into … //SQL語句
</insert>
這種辦法,會對注入的 實體類,自動加入 id 的值。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM