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





基于javaweb的SSM网上电商系统(java+ssm+mysql+tomcat+jsp)
一、项目简述
功能:本系统分用户前台和管理员后台。 前台展示+后台管理,前台界面可实现用户登录,用户注 册,商品展示,商品明细展示,用户信息修改,密码修 改,购物车添加,商品购买,商品结算,订单查询,购物 车查询,后台管理可实现商品管理,订单管理,用户管理
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui等等。
——————————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
|
@Controller @RequestMapping("/index") public class IndexController{ @Autowired private GoodService goodService; @Autowired private TypeService typeService;
@GetMapping("/index") public String index(HttpServletRequest request){ request.setAttribute("flag", 1); List<Goods> todayList = goodService.getListByTopType(Tops.TYPE_TODAY, 1, 6);
|
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
| return "/admin/admin_reset.jsp"; }
@PostMapping("/adminReset") public String adminReset(int id, String password, HttpServletRequest request, @RequestParam(required=false, defaultValue="1") int page) { adminService.update(id, password); return "redirect:adminList?page="+page; }
@PostMapping("/adminSave") public String adminSave(Admins admin, HttpServletRequest request, @RequestParam(required=false, defaultValue="1") int page) { if (Objects.nonNull(adminService.getByUsername(admin.getUsername()))) { request.setAttribute("msg", "用户名已存在!"); return "/admin/admin_add.jsp"; } adminService.add(admin); return "redirect:adminList?flag=5&page="+page; }
@GetMapping("/adminDelete") public String adminDelete(int id, @RequestParam(required=false, defaultValue="1") int page) { adminService.delete(id); return "redirect:adminList?flag=5&page="+page; }
@PostMapping("upload") public @ResponseBody Map<String, Object> upload(MultipartFile imgFile) throws Exception { Map<String, Object> map = new HashMap<>(); if (Objects.nonNull(imgFile) && !imgFile.isEmpty()) { map.put("error", 0);
|
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
| dataStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); dataStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); Font dataFont = wb.createFont(); dataFont.setFontHeightInPoints((short) 12); dataFont.setFontName("宋体"); dataStyle.setFont(dataFont); Iterator<T> it = dataList.iterator(); int index = 0; while (it.hasNext()) { index++; row = sheet.createRow(index); HSSFCell sequenceCellValue = row.createCell(0); sequenceCellValue.setCellValue(index); sequenceCellValue.setCellStyle(dataStyle); sheet.autoSizeColumn(0); T t = (T) it.next(); for (int i = 0; i < fieldArray.length; i++) { HSSFCell dataCell = row.createCell(i + 1); dataCell.setCellStyle(dataStyle); sheet.autoSizeColumn(i + 1); String fieldName = fieldArray[i]; String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); Class<? extends Object> tCls = t.getClass(); Method getMethod = tCls.getMethod(getMethodName, new Class[] {}); Object value = getMethod.invoke(t, new Object[] {}); if (value != null) { dataCell.setCellValue(value.toString()); } } }
OutputStream outputStream = response.getOutputStream(); wb.write(outputStream); wb.close(); outputStream.flush(); outputStream.close(); return wb; }
|
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
| public class IndexInterceptor extends HandlerInterceptorAdapter{
@Autowired private TypeService typeService; @Autowired private CartService cartService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { request.setAttribute("typeList", typeService.getList()); String uri = request.getRequestURI(); if(uri.contains("index/cart") || uri.contains("index/order") || uri.contains("index/my")) { Object user = request.getSession().getAttribute("user"); if (Objects.isNull(user)) { response.sendRedirect("login"); return false; } } return true; }
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { String uri = request.getRequestURI(); if(uri.contains("index/cart")) { Users user = (Users) request.getSession().getAttribute("user"); request.getSession().setAttribute("cartCount", cartService.getCount(user.getId())); } super.postHandle(request, response, handler, modelAndView); }
} package com.config;
|
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
| Users user = (Users) session.getAttribute("user"); return cartService.save(goodId, user.getId()); }
@PostMapping("/cartAdd") public @ResponseBody boolean cartAdd(int id){ return cartService.add(id); }
@PostMapping("/cartLess") public @ResponseBody boolean cartLess(int id){ return cartService.less(id); }
@PostMapping("/cartDelete") public @ResponseBody boolean cartDelete(int id){ return cartService.delete(id); }
@GetMapping("/order") public String order(HttpServletRequest request, HttpSession session, @RequestParam(required=false, defaultValue="1")int page, @RequestParam(required=false, defaultValue="6")int size) throws UnsupportedEncodingException{ Users user = (Users) session.getAttribute("user"); request.setAttribute("orderList", orderService.getListByUserid(user.getId(), page, size)); request.setAttribute("pageHtml", PageUtil.getPageHtml(request, orderService.getCountByUserid(user.getId()), page, size)); return "/index/order.jsp"; }
@PostMapping("/orderAdd")
|
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 IndexInterceptor extends HandlerInterceptorAdapter{
@Autowired private TypeService typeService; @Autowired private CartService cartService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { request.setAttribute("typeList", typeService.getList()); String uri = request.getRequestURI(); if(uri.contains("index/cart") || uri.contains("index/order") || uri.contains("index/my")) { Object user = request.getSession().getAttribute("user"); if (Objects.isNull(user)) { response.sendRedirect("login"); return false; } } return true; }
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { String uri = request.getRequestURI(); if(uri.contains("index/cart")) { Users user = (Users) request.getSession().getAttribute("user"); request.getSession().setAttribute("cartCount", cartService.getCount(user.getId())); } super.postHandle(request, response, handler, modelAndView); }
} package com.config;
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=351422292105200fh
https://javayms.pages.dev?id=351422292105200fh