作者主页:夜未央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
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
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
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
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