Java项目:基于ssm的水果商城系统

作者主页:夜未央5788

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目分为前后台,前台为普通用户登录,后台为管理员登录;
管理员角色包含以下功能:
管理员登录,类目管理,用户管理,商品管理,订单管理,发货管理,提交发货,公告管理,留言管理,日志查看等功能。

用户角色包含以下功能:

用户登录,用户首页,查看公告,提交留言,查看商品详情,加入购物车,商品结算等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 5.7版本;

6.是否Maven项目:是;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:JSP+CSS+JavaScript+jquery+bootstrap+echarts

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/fruitshop 登录
用户账号/密码: user/123456

管理员账号/密码:admin/admin

运行截图

前台界面

 

 

 

 

 

 

后台界面

 

 

 

 

 

 

 

代码相关

购物车管理控制器

@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;
    @Autowired
    private ItemService itemService;

    /**
     * 加入购物车
     *
     * @param request
     * @param car
     * @return
     */
    @RequestMapping("/addcar")
    @ResponseBody
    public String addcar(HttpServletRequest request, Car car) {
        JSONObject json = new JSONObject();
        Object userId = request.getSession().getAttribute("userId");
        //如果未登录,返回0,提示先登录
        if (userId == null) {
            json.put(Consts.RES, 0);
            return json.toJSONString();
        }
        //保存到购物车
        Item item = itemService.getById(car.getItemId());
        car.setUserId(Integer.valueOf(userId.toString()));
        String price = item.getPrice();
        Double value = Double.valueOf(price);
        car.setPrice(value);
        // BigDecimal bigDecimal = new BigDecimal(value).setScale(2,BigDecimal.ROUND_UP);
        if (item.getZk() != null) {
            value = value * item.getZk() / 10;
            BigDecimal bigDecimal = new BigDecimal(value).setScale(2, RoundingMode.UP);
            car.setPrice(bigDecimal.doubleValue());
        }
        Integer num = car.getNum();
        Double t = value * num;
        BigDecimal bigDecimal = new BigDecimal(t).setScale(2, RoundingMode.UP);
        Double tDouble = bigDecimal.doubleValue();
        car.setTotal(tDouble + "");
        carService.insert(car);
        json.put(Consts.RES, 1);
        return json.toJSONString();
    }

    /**
     * 跳转到购物车页面
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/findBySql")
    public String findBySql(Model model, HttpServletRequest request) {
         Object userId = request.getSession().getAttribute("userId");
         if(userId==null){
             return "redirect:/login/uLogin";

         }
         Integer id = Integer.valueOf(userId.toString());
         String sql = "select * from car where user_id="+id+" order by id";
        List<Car> carList = carService.listBySqlReturnEntity(sql);
        model.addAttribute("list",carList);
        return "/car/carview";
    }

    /**
     * 删除购物车
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(Integer id){
        carService.deleteById(id);
        return "success";
    }
}

类目管理控制器

@Controller
@RequestMapping("/itemCategory")
public class ItemCategoryController extends BaseController {

    @Autowired
    private ItemCategoryService itemCategoryService;

    /**
     * 分页查询类目列表
     */
    @RequestMapping("/findBySql")
    public String findBySql(Model model,ItemCategory itemCategory){
        String sql = "select * from item_category where isDelete = 0 and pid is null order by id";
        Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
        model.addAttribute("pagers",pagers);
        model.addAttribute("obj",itemCategory);
        return "itemCategory/itemCategory";
    }

    /**
     *转向添加一级分类页面
     * @return
     */
    @RequestMapping("/add")
    public String addItemCategory(){

        return "/itemCategory/add";
    }
    /**
     *转向添加二级分类页面
     * @return
     */
    @RequestMapping("/add2")
    public String addItemCategory2(Model model,Integer pid){
        model.addAttribute("pid",pid);
        return "/itemCategory/add2";
    }

    /**
     * 跳转到修改类目页面
     * @return
     */
    @RequestMapping("/update")
    public String updateItemCategory(Integer id,Model model){
        ItemCategory itemCategory = itemCategoryService.load(id);
        model.addAttribute("item",itemCategory);
        return "/itemCategory/update";
    }
    /**
     * 跳转到修改二级类目页面
     * @return
     */
    @RequestMapping("/updateTwo")
    public String updateTwoItemCategory(Integer id,Model model){
        ItemCategory itemCategory = itemCategoryService.load(id);
        model.addAttribute("item",itemCategory);
        return "/itemCategory/update2";
    }
    /**
     * 添加一级类目
     * @param itemCategory
     * @return
     */
    @RequestMapping("/exadd")
    public String exaddItemCategory(ItemCategory itemCategory){
        itemCategory.setIsDelete(0);
        itemCategoryService.insert(itemCategory);
        return "redirect:/itemCategory/findBySql";
      //  return "itemCategory/itemCategory";
    }
    /**
     * 添加二级类目
     * @param itemCategory
     * @return
     */
    @RequestMapping("/exadd2")
    public String exaddItemCategory2(ItemCategory itemCategory){
        itemCategory.setIsDelete(0);
        Integer pid = itemCategory.getPid();
        itemCategoryService.insert(itemCategory);
        return "redirect:/itemCategory/findBySql2.action?pid="+pid;
        //  return "itemCategory/itemCategory";
    }

    /**
     * 修改一级目录
     * @param itemCategory
     * @return
     */
   @RequestMapping("/exupdate")
    public String exupdateItemCategory(ItemCategory itemCategory){
       itemCategory.setIsDelete(0);
       String i = itemCategory.getName();
        itemCategoryService.updateById(itemCategory);
       return "redirect:/itemCategory/findBySql.action";
   }
    /**
     * 修改二级目录
     * @param itemCategory
     * @return
     */
    @RequestMapping("/exupdate2")
    public String exupdateTwoItemCategory(ItemCategory itemCategory){
        itemCategory.setIsDelete(0);
        String i = itemCategory.getName();
        Integer pid = itemCategory.getPid();
        itemCategoryService.updateById(itemCategory);
        return "redirect:/itemCategory/findBySql2.action?pid="+pid;
     //   return "redirect:/itemCategory/findBySql2.action?pid="+pid;
    }
    /**
     * 删除一个类目
     * @param id
     * @return
     */
   @RequestMapping("/delete")
    public String deleteItemCategory(Integer id){
       //把对应类目的isdelete改为1后更新
       ItemCategory itemCategory = itemCategoryService.load(id);
       itemCategory.setIsDelete(1);
       itemCategoryService.updateById(itemCategory);
       //如果类目下有子类目,把对应类目的isdelete改为1后更新
       String sql = "update item_category set isDelete=1 where pid="+id;
       itemCategoryService.updateBysql(sql);
       return "redirect://itemCategory/findBySql.action";
   }

    /**
     * 删除一个二级类目
     * @param id
     * @return
     */
    @RequestMapping("/deleteTwo")
    public String deleteTwoItemCategory(Integer id){
        //把对应类目的isdelete改为1后更新
        ItemCategory itemCategory = itemCategoryService.load(id);
        itemCategory.setIsDelete(1);
        itemCategoryService.updateById(itemCategory);
        return "redirect://itemCategory/findBySql2.action?pid="+itemCategory.getPid();
    }

    /**
     * 查找二级目录
     * @param pid
     * @param model
     * @return
     */
   @RequestMapping("findBySql2")
    public String findBySql2ItemCategory(Integer pid,Model model){
       //查找pid=id的类目
       String sql = "select * from item_category where isDelete=0 and pid="+pid;
       List<ItemCategory> list = itemCategoryService.listBySqlReturnEntity(sql);
       Pager<ItemCategory> pagers = itemCategoryService.findBySqlRerturnEntity(sql);
       model.addAttribute("pagers",pagers);
       model.addAttribute("ItemCategoryList",list);
       model.addAttribute("pid",pid);
       return "itemCategory/Sdirectory";
   }
}

 订单详情管理控制器

@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 获取订单详情列表
     * @param model
     * @param orderDetail
     * @return
     */
    @RequestMapping("/findbysql")
    public String OrderDetailList(Model model,OrderDetail orderDetail){
        String sql = "select * from order_detail where status = 0 and order_id = "+orderDetail.getOrderId();
        Pager<OrderDetail> pagers = orderDetailService.findBySqlRerturnEntity(sql);
        model.addAttribute("pagers",pagers);
        model.addAttribute("obj",orderDetail);
        return "/orderDetail/orderDetailList";
    }
}

如果也想学习本系统,下面领取。回复:216ssm

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜未央5788

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值