• 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

    运行截图

    用户角色

     

     

     

     

     

     管理员角色

     

     

     

     

    相关代码

    管理员控制器

    1. package com.smzy.controller;
    2. import com.smzy.pojo.Admin;
    3. import com.smzy.pojo.User;
    4. import com.smzy.service.AdminService;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.ui.Model;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import org.springframework.web.bind.annotation.RequestParam;
    10. import javax.servlet.http.HttpSession;
    11. @Controller
    12. public class AdminController {
    13. @Autowired
    14. private AdminService adminService;
    15. @RequestMapping("/aLogin")
    16. public String login(Model model, @RequestParam("name") String name,
    17. @RequestParam("password") String password,
    18. HttpSession session2) {
    19. Admin admin = adminService.get(name, password);
    20. if (null == admin) {
    21. model.addAttribute("msg", "用户名或密码错误");
    22. return "admin/adminLogin";
    23. }
    24. session2.setAttribute("admin", admin);
    25. return "redirect:admin/listCategory";
    26. }
    27. @RequestMapping("/adminLogout")
    28. public String logout(HttpSession session2) {
    29. session2.removeAttribute("admin");
    30. return "redirect:admin";
    31. }
    32. }

    分类控制器

    1. package com.smzy.controller;
    2. import com.smzy.pojo.Category;
    3. import com.smzy.service.CategoryService;
    4. import org.junit.Test;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.ui.Model;
    8. import org.springframework.web.bind.annotation.RequestMapping;
    9. import java.util.List;
    10. @Controller
    11. @RequestMapping("/admin")
    12. public class CategoryController {
    13. @Autowired
    14. private CategoryService categoryService;
    15. @RequestMapping("/listCategory")
    16. public String findAll(Model model) {
    17. List categories = categoryService.findAll();
    18. model.addAttribute("categories",categories);
    19. return "admin/listCategory";
    20. }
    21. @RequestMapping("/editCategory")
    22. public String edit(Category category , Model model) {
    23. model.addAttribute("category",category);
    24. return "admin/editCategory";
    25. }
    26. @RequestMapping("/updateCategory")
    27. public String update(Category category) {
    28. categoryService.update(category);
    29. return "redirect:listCategory";
    30. }
    31. }

    订单控制器

    1. package com.smzy.controller;
    2. import com.smzy.pojo.Order;
    3. import com.smzy.service.OrderService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.ui.Model;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import java.util.Date;
    9. import java.util.List;
    10. @Controller
    11. @RequestMapping("/admin")
    12. public class OrderController {
    13. @Autowired
    14. private OrderService orderService;
    15. @RequestMapping("/listOrder")
    16. public String findAll(Model model) {
    17. List orders = orderService.findAll();
    18. model.addAttribute("orders",orders);
    19. return "admin/listOrder";
    20. }
    21. @RequestMapping("/updateOrder")
    22. public String update(Order order) {
    23. orderService.update(order);
    24. return "redirect:listOrder";
    25. }
    26. @RequestMapping("/orderDelivery")
    27. public String delivery(Integer order_id) {
    28. Order order = orderService.get(order_id);
    29. order.setDelivery_date(new Date());
    30. order.setStatus(OrderService.waitConfirm);
    31. orderService.update(order);
    32. return "redirect:listOrder";
    33. }
    34. }

    用户控制器

    1. package com.smzy.controller;
    2. import com.smzy.pojo.User;
    3. import com.smzy.service.UserService;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.ui.Model;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RequestParam;
    9. import javax.servlet.http.HttpSession;
    10. import java.util.HashMap;
    11. import java.util.List;
    12. import java.util.Map;
    13. @Controller
    14. @RequestMapping("/admin")
    15. public class UserController {
    16. @Autowired
    17. private UserService userService;
    18. @RequestMapping("/listUser")
    19. public String findAll(Model model) {
    20. List users = userService.findAll();
    21. model.addAttribute("users",users);
    22. return "admin/listUser";
    23. }
    24. @RequestMapping("/editUser")
    25. public String edit(Model model ,Integer id) {
    26. User user = userService.get(id);
    27. model.addAttribute("user",user);
    28. return "admin/editUser";
    29. }
    30. @RequestMapping("/updateUser")
    31. public String update(Integer id,String password) {
    32. userService.updatePassword(id,password);
    33. return "redirect:listUser";
    34. }
    35. }

    产品控制器

    1. package com.smzy.controller;
    2. import com.smzy.pojo.Category;
    3. import com.smzy.pojo.Product;
    4. import com.smzy.pojo.ProductImage;
    5. import com.smzy.service.CategoryService;
    6. import com.smzy.service.ProductImageService;
    7. import com.smzy.service.ProductService;
    8. import com.smzy.service.PropertyValueService;
    9. import org.springframework.beans.factory.annotation.Autowired;
    10. import org.springframework.stereotype.Controller;
    11. import org.springframework.ui.Model;
    12. import org.springframework.web.bind.annotation.RequestMapping;
    13. import javax.servlet.http.HttpServletRequest;
    14. import java.io.File;
    15. import java.util.List;
    16. @Controller
    17. @RequestMapping("/admin")
    18. public class ProductController {
    19. @Autowired
    20. private ProductService productService;
    21. @Autowired
    22. private CategoryService categoryService;
    23. @Autowired
    24. private ProductImageService productImageService;
    25. @Autowired
    26. private PropertyValueService propertyValueService;
    27. @RequestMapping("/listProduct")
    28. public String findAll(Model model,Integer category_id) {
    29. List products = productService.findAll(category_id);
    30. model.addAttribute("products",products);
    31. Category category = categoryService.get(category_id);
    32. model.addAttribute("category",category);
    33. return "admin/listProduct";
    34. }
    35. @RequestMapping("/addProductView")
    36. public String addView(Model model,Integer category_id) {
    37. Category category = categoryService.get(category_id);
    38. model.addAttribute("category",category);
    39. return "admin/addProductView";
    40. }
    41. @RequestMapping("/addProduct")
    42. public String add(Product product) {
    43. productService.add(product);
    44. ProductImage productImage = new ProductImage();
    45. productImage.setProduct_id(product.getId());
    46. for(int i = 1;i <= 5 ;i++) {
    47. productImageService.add(productImage);
    48. }
    49. return "redirect:listProduct?category_id=" + product.getCategory_id();
    50. }
    51. /* @RequestMapping("/deleteProduct")
    52. public String delete(Integer id,HttpServletRequest request) {
    53. productImageService.deleteByProductId(id);
    54. String path = request.getSession().getServletContext().getRealPath("" + id);
    55. deleteDir(new File(path));
    56. propertyValueService.deleteByProductId(id);
    57. int category_id = productService.get(id).getCategory_id();
    58. productService.delete(id);
    59. return "redirect:listProduct?category_id=" + category_id;
    60. }*/
    61. /* public static boolean deleteDir(File dir) {
    62. if(dir.isDirectory()){
    63. String[] children = dir.list();
    64. for(int i = 0 ;i < children.length;i++ ) {
    65. boolean success = deleteDir(new File(dir, children[i]));
    66. if(!success) {
    67. return false;
    68. }
    69. }
    70. }
    71. return dir.delete();
    72. }*/
    73. @RequestMapping("/editProduct")
    74. public String edit(Integer id, Model model) {
    75. Product product = productService.get(id);
    76. model.addAttribute("product",product);
    77. Category category = categoryService.get(product.getCategory_id());
    78. model.addAttribute("category",category);
    79. return "admin/editProduct";
    80. }
    81. @RequestMapping("/updateProduct")
    82. public String update(Product product) {
    83. productService.update(product);
    84. return "redirect:listProduct?category_id=" + product.getCategory_id();
    85. }
    86. }

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

  • 相关阅读:
    心理软件使用问题三
    《TCP/IP网络编程》阅读笔记--I/O复用
    海泰前沿技术|隐私计算技术在医疗数据保护中的应用
    浏览器中的音视频知识总结v1.0(工作中需要和视频打交道必看!)
    Vue3引入腾讯地图,点击坐标后实时获取经纬度
    操作系统学习笔记2 | 操作系统接口
    LeetCode--1445. 苹果和桔子
    C++之模板——初阶
    3D激光SLAM:ALOAM---gazebo仿真测试场景搭建
    论文阅读【时间序列】TimeMixer (ICLR2024)
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126496896