springboot整合项目-商城项目展示购物车功能

展示购物车列表

1.持久层

1.规划sql语句

#多表查询如果字段不重复则不需要要声明字段属于那种表
select cid,uid,pid,t_cart.price,t_cart.num,t_product.title,t_product.imgae,t_product.price as realprice
from  t_cart left join t_product on  t_cart.pid = t_product.id  where  uid =#{uid}  order by t_cart.createdTime DESC 

2.设计抽象方法

VO:value object :值对象,当进行select查询,查询的结果数据多表中的内容,此时发现结果集不能直接使用某个pojo实体类来接收,pojo实体类不能包含多表查询出来的结果,解决方法:重新去构建一个新的对象
这个对象用户存储所查询出来的结果集对应的映射,所有把这个的对象称之为值对象。

3.测试

  /**
     * 测试通过uid来查找某个用户的购物车
     */
    @Test
    void  testFindByUid(){
        log.info("查询的结果:{}",cartMapper.findByUid(10));
    }

业务层

1.规划异常

无异常规划

2.接口与方法设计

 /**
     *查找uid的收货地址
     * @param uid
     * @return
     */
    @Override
    public List<CartVo> getVOByUid(Integer uid) {
        return cartMapper.findByUid(uid);
    }

4.测试

控制层

1.处理异常

2.请求设计

/carts/
/HttpSession session
/get
/JsonResult<List>
getVOByUid(HttpSession session)

posted @ 2022-11-09 13:50  wiselee/  阅读(76)  评论(0编辑  收藏  举报