使用通用mapper的insertSelective插入數據后,實體類的初始為null的id主動映射為數據庫自增長的id


代碼如下:

     spuBo.setId(null);
spuBo.setSaleable(true);
spuBo.setValid(true);
spuBo.setCreateTime(new Date());
spuBo.setLastUpdateTime(spuBo.getCreateTime());
this.spuMapper.insertSelective(spuBo);



// 新增spu_detail
SpuDetail spuDetail = spuBo.getSpuDetail();
spuDetail.setSpuId(spuBo.getId());
this.spuDetailMapper.insertSelective(spuDetail);
// 新增sku和stock
saveSkuAndStock(spuBo);


開始的spuBo的id為null,進行插入操作之后,id不再是Null,而是對應數據庫中的新插入的id,
於是下面的代碼就可以使用這個id進行操作了


免責聲明!

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



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