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

使用说明

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

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

运行截图

用户角色

 

 

 

 

 

 管理员角色

 

 

 

 

相关代码

管理员控制器

package com.smzy.controller;

import com.smzy.pojo.Admin;
import com.smzy.pojo.User;
import com.smzy.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/aLogin")
    public String login(Model model, @RequestParam("name") String name,
                        @RequestParam("password") String password,
                        HttpSession session2) {
        Admin admin = adminService.get(name, password);
        if (null == admin) {
            model.addAttribute("msg", "用户名或密码错误");
            return "admin/adminLogin";
        }
        session2.setAttribute("admin", admin);
        return "redirect:admin/listCategory";
    }

    @RequestMapping("/adminLogout")
    public String logout(HttpSession session2) {
        session2.removeAttribute("admin");
        return "redirect:admin";
    }
}

分类控制器

package com.smzy.controller;

import com.smzy.pojo.Category;
import com.smzy.service.CategoryService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/listCategory")
    public String findAll(Model model) {
        List<Category> categories = categoryService.findAll();
        model.addAttribute("categories",categories);
        return "admin/listCategory";
    }

    @RequestMapping("/editCategory")
    public String edit(Category category , Model model) {
        model.addAttribute("category",category);
        return "admin/editCategory";
    }

    @RequestMapping("/updateCategory")
    public String update(Category category) {
        categoryService.update(category);
        return "redirect:listCategory";
    }
}

订单控制器

package com.smzy.controller;

import com.smzy.pojo.Order;
import com.smzy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/listOrder")
    public String findAll(Model model) {
        List<Order> orders = orderService.findAll();
        model.addAttribute("orders",orders);
        return "admin/listOrder";
    }

    @RequestMapping("/updateOrder")
    public String update(Order order) {
        orderService.update(order);
        return "redirect:listOrder";
    }

    @RequestMapping("/orderDelivery")
    public String delivery(Integer order_id) {
        Order order = orderService.get(order_id);
        order.setDelivery_date(new Date());
        order.setStatus(OrderService.waitConfirm);
        orderService.update(order);
        return "redirect:listOrder";
    }
}

用户控制器

package com.smzy.controller;

import com.smzy.pojo.User;
import com.smzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/listUser")
    public String findAll(Model model) {
        List<User> users = userService.findAll();
        model.addAttribute("users",users);
        return "admin/listUser";
    }
    @RequestMapping("/editUser")
    public String edit(Model model ,Integer id) {
        User user = userService.get(id);
        model.addAttribute("user",user);
        return "admin/editUser";
    }

    @RequestMapping("/updateUser")
    public String update(Integer id,String password) {
        userService.updatePassword(id,password);
        return "redirect:listUser";
    }


}

产品控制器

package com.smzy.controller;

import com.smzy.pojo.Category;
import com.smzy.pojo.Product;
import com.smzy.pojo.ProductImage;
import com.smzy.service.CategoryService;
import com.smzy.service.ProductImageService;
import com.smzy.service.ProductService;
import com.smzy.service.PropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductImageService productImageService;

    @Autowired
    private PropertyValueService propertyValueService;

    @RequestMapping("/listProduct")
    public String findAll(Model model,Integer category_id) {
        List<Product> products = productService.findAll(category_id);
        model.addAttribute("products",products);
        Category category = categoryService.get(category_id);
        model.addAttribute("category",category);
        return "admin/listProduct";
    }

    @RequestMapping("/addProductView")
    public String addView(Model model,Integer category_id) {
        Category category = categoryService.get(category_id);
        model.addAttribute("category",category);
        return "admin/addProductView";
    }
    @RequestMapping("/addProduct")
    public String add(Product product) {
        productService.add(product);
        ProductImage productImage = new ProductImage();
        productImage.setProduct_id(product.getId());
        for(int i = 1;i <= 5 ;i++) {
            productImageService.add(productImage);
        }
        return "redirect:listProduct?category_id=" + product.getCategory_id();
    }

   /*  @RequestMapping("/deleteProduct")
   public String delete(Integer id,HttpServletRequest request) {
        productImageService.deleteByProductId(id);
        String path = request.getSession().getServletContext().getRealPath("" + id);
        deleteDir(new File(path));
        propertyValueService.deleteByProductId(id);
        int category_id = productService.get(id).getCategory_id();
        productService.delete(id);
        return "redirect:listProduct?category_id=" + category_id;
    }*/

/*    public static boolean deleteDir(File dir) {
        if(dir.isDirectory()){
            String[] children = dir.list();
            for(int i = 0 ;i < children.length;i++ ) {
                boolean success = deleteDir(new File(dir, children[i]));
                if(!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }*/
    @RequestMapping("/editProduct")
    public String edit(Integer id, Model model) {
        Product product = productService.get(id);
        model.addAttribute("product",product);
        Category category = categoryService.get(product.getCategory_id());
        model.addAttribute("category",category);
        return "admin/editProduct";
    }

    @RequestMapping("/updateProduct")
    public String update(Product product) {
        productService.update(product);
        return "redirect:listProduct?category_id=" + product.getCategory_id();
    }
}

如果也想学习本系统,下面领取。关注并回复:147ssm 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜未央5788

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

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

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

打赏作者

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

抵扣说明:

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

余额充值