使用通用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