赞
踩
<resultMap id="shoppingCartProduct" type="shoppingCartProductVo"> <id property="shoppingCartId" column="shopping_cart_id"></id> <result property="productId" column="product_id"></result> <result property="num" column="num"></result> <result property="productName" column="product_name"></result> <result property="productTitle" column="product_title"></result> <result property="productIntro" column="product_intro"></result> <result property="productPicture" column="product_picture"></result> <result property="productPrice" column="product_price"></result> <result property="productSellingPrice" column="product_selling_price"></result> </resultMap> <select id="selectShoppingCartByIds" resultMap="shoppingCartProduct"> select s.shopping_cart_id, s.num, s.product_id, p.product_name, p.product_title, p.product_intro, p.product_picture, p.product_price, p.product_selling_price FROM shopping_cart AS s left JOIN product AS p ON s.product_id = p.product_id WHERE s.shopping_cart_id in (<foreach collection="list" index="id" separator=","> #{id} </foreach>) </select>
@Override @Transactional public GetData postOrders(List<Long> shoppingCartIds, Long userId) { //1.判断用户是否存在 if (msUserMapper.FindUser(userId) == null) { GetData getData=new GetData(500,"无此账号",null); return getData; } //2.生成订单 Orders orders=new Orders(); orders.setOrderNum(UUID.randomUUID().toString()); orders.setUserId(userId); orders.setOrderTime(new Date()); orderProductMapper.addOrders(orders); System.out.println(orders.getOrderId()); System.out.println(orders.getOrderId().getClass().getTypeName()); System.out.println(shoppingCartIds); //3.查询购物车商品数据 List<ShoppingCartProductVo> shoppingCartProductVos = productMapper.selectShoppingCartByIds(shoppingCartIds); System.out.println(shoppingCartProductVos.size()); System.out.println(shoppingCartProductVos); List<OrdersDtl> ordersDtls = new ArrayList<>(); for (ShoppingCartProductVo vo : shoppingCartProductVos) { OrdersDtl ordersDtl = new OrdersDtl(); ordersDtl.setOrderId(orders.getOrderId()); ordersDtl.setProductId(vo.getProductId()); ordersDtl.setProductIntro(vo.getProductIntro()); ordersDtl.setProductName(vo.getProductName()); ordersDtl.setProductPicture(vo.getProductPicture()); ordersDtl.setProductPrice(vo.getProductPrice()); ordersDtl.setProductSellingPrice(vo.getProductSellingPrice()); ordersDtl.setProductTitle(vo.getProductTitle()); ordersDtl.setNum(vo.getNum()); ordersDtls.add(ordersDtl); } System.out.println(ordersDtls); orderProductMapper.addBatchOrderDtlsInt(ordersDtls); System.out.println(1); int rs =shoppingCartMapper.deleteShoppingCarts(shoppingCartIds); if (rs>0){ GetData getData=new GetData(200,"操作成功",null); return getData; }else { GetData getData=new GetData(500,"操作成功",rs); return getData; } }
# 配置mybatis
mybatis:
# mapper配置文件
mapper-locations: classpath:mapper/*.xml
# resultType别名,没有这个配置resultType包名要写全,配置后只要写类名
type-aliases-package: com.example.demo.com.mashang.dao
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
local-cache-scope: statement # 设置一级缓存关闭,mybatis默认开启
select
s.num, s.product_id, p.product_name, p.product_title, p.product_intro, p.product_picture, p.product_price, p.product_selling_price
FROM shopping_cart AS s
INNER JOIN product AS p
ON s.product_id = p.product_id
WHERE s.shopping_cart_id
in ( ? , ? , ? )
<resultMap id="shoppingCartProduct" type="shoppingCartProductVo"> <id property="shoppingCartId" column="shopping_cart_id"></id> <result property="productId" column="product_id"></result> <result property="num" column="num"></result> <result property="productName" column="product_name"></result> <result property="productTitle" column="product_title"></result> <result property="productIntro" column="product_intro"></result> <result property="productPicture" column="product_picture"></result> <result property="productPrice" column="product_price"></result> <result property="productSellingPrice" column="product_selling_price"></result> </resultMap> <select id="selectShoppingCartByIds" resultMap="shoppingCartProduct"> select s.shopping_cart_id, s.num, s.product_id, p.product_name, p.product_title, p.product_intro, p.product_picture, p.product_price, p.product_selling_price FROM shopping_cart AS s left JOIN product AS p ON s.product_id = p.product_id WHERE s.shopping_cart_id in (<foreach collection="list" item="id" separator=","> #{id} </foreach>) </select>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。