zoukankan      html  css  js  c++  java
  • 根据对应规格更新规格对应数量,库存

    /**
    * 减库存
    * @param json 商品规格id 和 数量 json [{"standardid":"79","count":"5"},{"standardid":"81","count":"3"},{"standardid":"82","count":"2"},{"standardid":"83","count":"2"}]
    **/
    @RequestMapping(value = "/UpdateReduceStocks.json", method = RequestMethod.GET)
    @ResponseBody
    public Integer UpdateReduceStocks(String json) {
    HashMap<String , Object> map = new HashMap<>();
    net.sf.json.JSONArray jsonArr = net.sf.json.JSONArray.fromObject(json);
    String standardid[] = new String[jsonArr.size()];
    String count[] = new String[jsonArr.size()];
    for (int i = 0; i < jsonArr.size(); i++) {
    standardid[i] = jsonArr.getJSONObject(i).getString("standardid");
    count[i] = jsonArr.getJSONObject(i).getString("count");
    }
    for (int i = 0; i < standardid.length; i++) {
    System.out.print("规格id "+standardid[i]+" ");
    System.out.print("数量 "+count[i]);
    System.out.println();
    Integer result = groupGoodsService.UpdateReduceStocks(parseInt(standardid[i]), parseInt(count[i]));
    }

    return 1;
    }

    Service:
    //减库存
    Integer UpdateReduceStocks(Integer standardId,Integer count);

    Mapper.xml
    <!--减库存-->1,0表示按顺序插入,不然不能插入多个或者改配置
    <update id="UpdateReduceStocks" parameterType="map">
    UPDATE standard set stock = stock-#{1} where standard_id = #{0}
    </update>








    境随心转而悦,心随境转而烦
  • 相关阅读:
    scnner02 (nextLine)
    Scanner01
    Spring 框架 (初学)
    查询自己写了多少行代码
    jdbc事务
    jdbc(预编译插入数据)
    jdbc(java连接数据库)
    监听器扩展
    listener(监听器)
    Filter过滤器
  • 原文地址:https://www.cnblogs.com/tomingto/p/10848812.html
Copyright © 2011-2022 走看看