随笔 - 58  文章 - 0  评论 - 1  阅读 - 17万

使用通用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进行操作了
posted on   supress_Elon_Musk  阅读(4268)  评论(0编辑  收藏  举报
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示