Some of the built-in methods of tkmapper

Look at the sentences understood in the online class and some of the built-in methods of tkmapper

 First, the outer layer is a loop foreach loop

 

 Use the updateByExample method that comes with tkmapper to modify it based on the ID. Put the ID you need to modify in the criteria, which is the skuId, and then productSku is the content you want to modify.

                 //扣减库存
                for(ShoppingCartVO sc:list){
                    String skuId = sc.getSkuId();
                    int newStock = sc.getSkuStock() - Integer.parseInt(sc.getCartNum());

                    Example example = new Example(ProductSku.class);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("skuId",skuId);

                    ProductSku productSku = new ProductSku();
                    productSku.setStock(newStock);

                    int k = productSkuMapper.updateByExample(productSku, example);

                }

 Just record your own learning

Guess you like

Origin blog.csdn.net/Feixiangdechenyu/article/details/131232650