SSM实现网上商城 有聊天功能

2023-11-11

1.项目介绍

     实现一个网上商城,商品信息展示,购物车,订单管理,个人中心,商品评价,商品搜索,地址管理,聊天,后台管理(商品增删改查),分类管理,活动管理,客服聊天回复

2.开发环境

  • 开发环境:IDEA/eclipse、Tomcat8.5+
  • 数据库:MySql
  • 前端主要使用Bootstrap以及JQuery,后端基于SpringMVC、Spring、MyBatis进行开发,使用Maven构建
  • activeMQ

 

 

 

相关代码

 

@Controller
public class OrderController {

    /*@Value("#{addressService}")*/
    @Autowired
    private AddressService addressService;

    @Autowired
    private ShopCartService shopCartService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private ActivityService activityService;

    @RequestMapping("/order")
    public String showOrder(HttpSession session, Model model) {

        User user = (User) session.getAttribute("user");
        if (user == null) {
            return "redirect:/login";
        }

        //查询当前用户的收货地址
        AddressExample addressExample = new AddressExample();
        addressExample.or().andUseridEqualTo(user.getUserid());
        List<Address> addressList = addressService.getAllAddressByExample(addressExample);

        model.addAttribute("address", addressList);

        //订单信息
        //获取当前用户的购物车信息
        ShopCartExample shopCartExample = new ShopCartExample();
        shopCartExample.or().andUseridEqualTo(user.getUserid());
        List<ShopCart> shopCart = shopCartService.selectByExample(shopCartExample);

        //获取购物车中的商品信息
        List<Goods> goodsAndImage = new ArrayList<>();

        Float totalPrice = new Float(0);
        Integer oldTotalPrice = 0;

        for (ShopCart cart:shopCart) {
            Goods goods = goodsService.selectById(cart.getGoodsid());

            List<ImagePath> imagePathList = goodsService.findImagePath(goods.getGoodsid());
            goods.setImagePaths(imagePathList);
            goods.setNum(cart.getGoodsnum());

            //活动信息
            Activity activity = activityService.selectByKey(goods.getActivityid());
            goods.setActivity(activity);

            if(activity.getDiscount() != 1) {
                goods.setNewPrice(goods.getPrice()*goods.getNum()* activity.getDiscount());
            } else if(activity.getFullnum() != null) {
                if (goods.getNum() >= activity.getFullnum()) {
                    goods.setNewPrice((float) (goods.getPrice()*(goods.getNum()-activity.getReducenum())));
                } else {
                    goods.setNewPrice((float) (goods.getPrice()*goods.getNum()));
                }
            } else {
                goods.setNewPrice((float) (goods.getPrice()*goods.getNum()));
            }
            totalPrice = totalPrice + goods.getNewPrice();
            oldTotalPrice = oldTotalPrice + goods.getNum() * goods.getPrice();
            goodsAndImage.add(goods);
        }

        model.addAttribute("totalPrice", totalPrice);
        model.addAttribute("oldTotalPrice", oldTotalPrice);
        model.addAttribute("goodsAndImage", goodsAndImage);

        return "orderConfirm";
    }

    @RequestMapping("/orderFinish")
    @ResponseBody
    public Msg orderFinish(Float oldPrice, Float newPrice, Boolean isPay, Integer addressid,HttpSession session) {
        User user = (User) session.getAttribute("user");

        //获取订单信息
        ShopCartExample shopCartExample = new ShopCartExample();
        shopCartExample.or().andUseridEqualTo(user.getUserid());
        List<ShopCart> shopCart = shopCartService.selectByExample(shopCartExample);

        //删除购物车
        for (ShopCart cart : shopCart) {
            shopCartService.deleteByKey(new ShopCartKey(cart.getUserid(),cart.getGoodsid()));
        }

        //把订单信息写入数据库
        Order order = new Order(null, user.getUserid(), new Date(), oldPrice, newPrice, isPay, false, false, false, addressid,null,null);
        orderService.insertOrder(order);
        //插入的订单号
        Integer orderId = order.getOrderid();

        //把订单项写入orderitem表中
        for (ShopCart cart : shopCart) {
            orderService.insertOrderItem(new OrderItem(null, orderId, cart.getGoodsid(), cart.getGoodsnum()));
        }

        return Msg.success("购买成功");
    }

}
@Controller
public class MainController {

    @Autowired
    private CateService cateService;

    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/main")
    public String showAllGoods(Model model, HttpSession session) {

        Integer userid;
        User user = (User) session.getAttribute("user");
        if (user == null) {
            userid = null;
        } else {
            userid = user.getUserid();
        }

        //数码分类
        List<Goods> digGoods = getCateGoods("数码", userid);
        model.addAttribute("digGoods", digGoods);

        //家电
        List<Goods> houseGoods = getCateGoods("家电", userid);
        model.addAttribute("houseGoods", houseGoods);

        //服饰
        List<Goods> colGoods = getCateGoods("服饰", userid);
        model.addAttribute("colGoods", colGoods);

        //书籍
        List<Goods> bookGoods = getCateGoods("书籍", userid);
        model.addAttribute("bookGoods", bookGoods);

        return "main";
    }

    public List<Goods> getCateGoods(String cate, Integer userid) {
        //查询分类
        CategoryExample digCategoryExample = new CategoryExample();
        digCategoryExample.or().andCatenameLike(cate);
        List<Category> digCategoryList = cateService.selectByExample(digCategoryExample);

        if (digCategoryList.size() == 0) {
            return null;
        }

        //查询属于刚查到的分类的商品
        GoodsExample digGoodsExample = new GoodsExample();
        List<Integer> digCateId = new ArrayList<Integer>();
        for (Category tmp:digCategoryList) {
            digCateId.add(tmp.getCateid());
        }
        digGoodsExample.or().andCategoryIn(digCateId);

        List<Goods> goodsList = goodsService.selectByExampleLimit(digGoodsExample);

        List<Goods> goodsAndImage = new ArrayList<>();
        //获取每个商品的图片
        for (Goods goods:goodsList) {
            //判断是否为登录状态
            if (userid == null) {
                goods.setFav(false);
            } else {
                Favorite favorite = goodsService.selectFavByKey(new FavoriteKey(userid, goods.getGoodsid()));
                if (favorite == null) {
                    goods.setFav(false);
                } else {
                    goods.setFav(true);
                }
            }

            List<ImagePath> imagePathList = goodsService.findImagePath(goods.getGoodsid());
            goods.setImagePaths(imagePathList);
            goodsAndImage.add(goods);
        }
        return goodsAndImage;
    }
}

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SSM实现网上商城 有聊天功能 的相关文章

  • 理解分组卷积与深度可分离卷积

    这两种卷积分别是在ResNext论文与MobileNet系列中体现的 貌似Xception中也有深度可分离卷积的体现 作用都很简单 为了降参 目录 1 分组卷积 group convolution 2 深度可分离卷积 depthwise s
  • 测试用例设计--等价类的几个例子

    等价类的设计思路 根据输入条件 确定等价类 包括有效等价类和无效等价类 建立等价类列表 为每个等价类规定一个唯一的编号 设计一个测试用例 使其尽可能多地覆盖尚未被覆盖的有效等价类 重复这一步 直到所有的有效等价类被覆盖完为止 设计一个测试用
  • 如何查看chrome浏览器插件位置 查看chrome浏览器插件位置的方法

    Chrome浏览器插件种类目繁多 插件支持功能也比较强大 Chrome浏览器内的下载的插件往往也可以被其他浏览器支持 那么如何查看chrome浏览器插件位置 想知道谷歌浏览器插件的存放位置小伙伴快来阅读下文教程 谷歌浏览器最新版下载2020
  • 面试大盘表 - 时间维护功能

    需求描述 由于本人主要负责干部和招聘板块 招聘板块接到了要做一个面试大盘表的需求 需要展示面试官的面试情况 还需要面试官维护自己的可面试时间 之后人资进行面试安排 然后面试者到手机端进行自主选择面试官和面试场次 最终展示 功能描述 移出维护
  • 联想全系列 Lenovo ThinkPad ThinkBook Thinkcenter ThinkStation 原厂恢复系统

    原厂恢复系统镜像 出厂预装正版系统 自带预装Office 自带一键恢复 联网自动激活系统 根据电脑型号或者MTM下载对应的系统恢复镜像 2022 4 30更新 型号后面括号里是MTM号 可对应个人电脑自行对应查找 如没有其对应机型可以Wei
  • C++入门泛型编程介绍

    目录 函数模板 函数模板格式 函数模板的实例化 补充 类模板 类模板的定义格式 类模板的实例化 非类型模板参数 模板特化 函数模板特化 类模板特化 全特化 偏特化 模板分离编译 模板总结 泛型编程 编写与类型无关的通用代码 是代码复用的一种
  • SQLite安装与使用

    在之前的文章中 给出了一个数据库知识的概览 数据库概览 本文介绍一些基础的 常用的SQLite数据库知识 SQLite基础 SQL基础语法 插入 INSERT INTO 表名 列名1 VALUES 列1值 修改 UPDATE 表名 SET
  • background-size属性详解

    css background size 属性详解 background size 指定背景图像大小 以象素或百分比显示 当指定为百分比时 大小会由所在区域的宽度 高度以及 background origin 图片的起始位置 的位置决定 还可
  • 解决lxml导入etree模块报错(或beautifulsoup使用xml解析器时报错)

    Linux下直接pip安装的lxml模块可能是不完整的 import lxml正常 但是from lxml import etree就会报错 ImportError cannot import name etree from lxml 同时
  • 关于Linux开发时,g++明明已经添加-I头文件路径,但是仍报“xxxx.h: No such file or directory“的错误

    之所以将这个bug写在这里 是因为我在ONVIF时遇到的问题 自己编写makefile编译时 明明C 添加了 I却仍然无法找到头文件路径 原因 I别连续在尾部添加 g 不一定能识别 解决是添加多个 I即可 例如 makefile中 INCL
  • 【Qt】问题解决:Unable to create a debugging engine.

    一 问题现象及原因 在 Qt Creator 中以调试模式运行程序时出现以下错误 在 Qt 中打开Tools gt Options gt Kits 发现 Debugger 里面没用可用的调试器 原因 在安装 Visual Studio 20
  • 直接使用POST方法登录网站

    浏览器在 POST 数据之后能够自动登录 那么我能不能在代码中直接模拟这个过程呢 于是我设定了这样的一个流程 1 设置浏览器的 headers 设置请求等 2 使用 httpfox 工具获取post data 3 将post data 写下
  • 线性代数_3、行列式的七大性质及推论

    性质 1 D T D T DT D 转置 定义 就是把行列进行调换 行变成列 列变成行 表述方式 D T
  • Vue-elementui 下拉框(el-dropdown)绑定点击事件

    ElementUI组件下拉框绑定点击事件无效的解决方案 在使用脚手架构建的项目中需要使用到下拉组建
  • nacos学习思路

    添加一个链接 使用和原理 nacos使用教程及原理简介 nacos多机房部署 一梦无痕bzy的博客 CSDN博客 1 核心概念 Namespace group service cluster instance 2 注册表结构 其实是一个双层
  • ELK日志监控平台(三)---kibana数据可视化

    目录 一 基本简介 编辑 二 安装 三 创建可视化访问量的指标 四 创建可视化访问量的垂直条形图 五 启动xpack安全验证 官放文档 Explore Kibana using sample data Kibana Guide 7 6 El

随机推荐