作者主页:夜未央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_gypxs_shop/ 登录
运行截图
前台界面
后台界面
相关代码
管理员控制器
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 {@Autowiredprivate 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 {@Autowiredprivate 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 {@Autowiredprivate 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.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 {@Autowiredprivate ProductService productService;@Autowiredprivate CategoryService categoryService;@Autowiredprivate ProductImageService productImageService;@Autowiredprivate 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();}
}
如果也想学习本系统,下面领取。关注并回复:188ssm