zoukankan      html  css  js  c++  java
  • 使用通用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进行操作了
  • 相关阅读:
    HTTP GET POST PUT DELETE 四种请求
    PHP表达式
    PHP基础
    文件存储
    动态加载布局文件
    Android新增控件
    Spring简介
    Hibenate配置篇
    无题
    struts常用标签与校验器
  • 原文地址:https://www.cnblogs.com/zxq-Study-Java/p/10044588.html
Copyright © 2011-2022 走看看