——————————DescriptionStart——————————
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明






基于javaweb的SSM+Maven游戏装备系统(java+ssm+jsp+bootstrap+mysql)
前台用户:
user1 123456
user2 123456
后台管理员:
admin 123456
项目介绍
本项目为前后台项目,前台为普通用户登录,后台为管理员登录;
管理员角色包含以下功能: 管理员登录,装备分类管理,装备管理、分类管理、属性管理,用户管理,订单管理等功能。
用户角色包含以下功能: 查看首页,查看装备详情,用户登录,查看购物车,提交订单,查看我的订单等功能。
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| @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(); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| model.addAttribute("category",category); return "admin/listProperty"; }
@RequestMapping("/addPropertyView") public String addPropertyView(Model model,Integer category_id) { Category category = categoryService.get(category_id); model.addAttribute("category" , category); return "admin/addPropertyView"; } @RequestMapping("/addProperty") public String add(Property property) { propertyService.add(property); return "redirect:listProperty?category_id=" + property.getCategory_id(); }
@RequestMapping("/deleteProperty") public String delete(Integer id) { Integer category_id = propertyService.get(id).getCategory_id(); propertyService.delete(id); return "redirect:listProperty?category_id=" + category_id; }
@RequestMapping("/editProperty") public String edit(Integer id,Model model) { Property property = propertyService.get(id); model.addAttribute("property",property); Category category = categoryService.get(property.getCategory_id()); model.addAttribute("category",category); return "admin/editProperty"; }
@RequestMapping("/updateProperty") public String update(Property property) { propertyService.update(property); return "redirect:listProperty?category_id=" + property.getCategory_id(); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| }
@RequestMapping("/createOrder") public String createOrder(Model model, Order order, HttpSession session) { User user = (User) session.getAttribute("user"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()); order.setOrder_code(orderCode); order.setCreate_date(new Date()); order.setUser_id(user.getId()); order.setStatus(OrderService.waitPay); List<OrderItem> orderItems = (List<OrderItem>) session.getAttribute("orderItems"); float total = orderService.addTotal(order, orderItems); return "redirect:payPage?order_id=" + order.getId() + "&total=" + total; }
@RequestMapping("/payed") public String payed(int order_id, float total, Model model) { Order order = orderService.get(order_id); order.setStatus(OrderService.waitDelivery); order.setPay_date(new Date()); orderService.update(order); model.addAttribute("order", order); return "payed"; }
@RequestMapping("addCart") @ResponseBody public String addCart(int product_id,int num,Model model,HttpSession session) { Product p = productService.get(product_id); User user = (User) session.getAttribute("user"); boolean found = false; List<OrderItem> ois = orderItemService.findByUserId(user.getId()); for(OrderItem oi :ois) { if(oi.getProduct().getId().intValue() == p.getId().intValue()) { oi.setNumber(oi.getNumber() + num); orderItemService.update(oi); found = true; break; } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| @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("/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);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| return "redirect:admin"; } }
@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);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class LoginInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request , HttpServletResponse response ,Object handler) throws Exception { HttpSession session = request.getSession(); String[] noNeedAuthPage = new String[] { "/youxizb/home", "/youxizb/searchProduct", "/youxizb/sortProduct", "/youxizb/showProduct", "/youxizb/login", "/youxizb/loginPage", "/youxizb/registerPage", "/youxizb/register", "/youxizb/registerSuccess", "/youxizb/checkLogin", "/youxizb/admin", "/youxizb/aLogin", "/youxizb/adminLogout", "/youxizb/knowledge", "/youxizb/advert" }; String uri = request.getRequestURI(); if(!Arrays.asList(noNeedAuthPage).contains(uri)) { User user = (User) session.getAttribute("user"); if(null == user) { response.sendRedirect("/youxizb/loginPage"); return false; } } return true; }
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { }
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { super.afterCompletion(request, response, handler, ex); } }
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=001023501103200zh
https://javayms.pages.dev?id=001023501103200zh