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







基于javaweb的SSM+Maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)
一、项目简述 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + css + JavaScript + JQuery + Ajax + layui+ maven等等。
——————————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 50 51 52 53
| @RequestMapping("/foreLogin") public String foreLogin(Customer customer, HttpSession session, Model model){ Customer cst = customerService.foreLogin(customer); if (cst!=null){ session.setAttribute("cst",cst); return "redirect:foreIndex"; }else { return "redirect:foreLoginMsg"; } }
@RequestMapping("/foreLoginMsg") public String foreLoginMsg(HttpServletRequest request){ request.setAttribute("msg","true"); return "forepage/forelogin"; }
@RequestMapping("/foreCstLoginOut") public String cstLoginOut(HttpSession session){ session.setAttribute("cst",null); return "redirect:foreIndex"; }
@RequestMapping("/forebuyone") public String forebuyone(HttpSession session, int pid, int number, float totalPrice){ Customer cst = (Customer) session.getAttribute("cst"); Product product = productService.get(pid);
int oiid = 0;
boolean find = false; List<OrderItem> orderItems = orderItemService.listByCustomer(cst.getId()); for (OrderItem oi : orderItems) { if(oi.getProduct().getId().intValue()==product.getId().intValue()){
|
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
| long maxSize = ((Long) conf.get("maxSize")).longValue();
if (!validType(suffix, (String[]) conf.get("allowFiles"))) { return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE); }
savePath = PathFormat.parse(savePath, originFileName);
String physicalPath = (String) conf.get("rootPath") + savePath;
InputStream is = fileStream.openStream(); State storageState = StorageManager.saveFileByInputStream(is, physicalPath, maxSize); is.close();
if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", originFileName + suffix); }
return storageState; } catch (FileUploadException e) { return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR); } catch (IOException e) { } return new BaseState(false, AppInfo.IO_ERROR); }
private static boolean validType(String type, String[] allowTypes) { List<String> list = Arrays.asList(allowTypes);
return list.contains(type); } } package com.demo.controller;
|
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
| return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA); }
String savePath = (String) conf.get("savePath"); String originFileName = fileStream.getName(); String suffix = FileType.getSuffixByFilename(originFileName);
originFileName = originFileName.substring(0, originFileName.length() - suffix.length()); savePath = savePath + suffix;
long maxSize = ((Long) conf.get("maxSize")).longValue();
if (!validType(suffix, (String[]) conf.get("allowFiles"))) { return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE); }
savePath = PathFormat.parse(savePath, originFileName);
String physicalPath = (String) conf.get("rootPath") + savePath;
InputStream is = fileStream.openStream(); State storageState = StorageManager.saveFileByInputStream(is, physicalPath, maxSize); is.close();
if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", originFileName + suffix); }
return storageState; } catch (FileUploadException e) { return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR); } catch (IOException e) { } return new BaseState(false, AppInfo.IO_ERROR); }
private static boolean validType(String type, String[] allowTypes) { List<String> list = Arrays.asList(allowTypes);
return list.contains(type); } } package com.demo.controller;
|
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
|
public class BinaryUploader {
public static final State save(HttpServletRequest request, Map<String, Object> conf) { FileItemStream fileStream = null; boolean isAjaxUpload = request.getHeader( "X_Requested_With" ) != null;
if (!ServletFileUpload.isMultipartContent(request)) { return new BaseState(false, AppInfo.NOT_MULTIPART_CONTENT); }
ServletFileUpload upload = new ServletFileUpload( new DiskFileItemFactory());
if ( isAjaxUpload ) { upload.setHeaderEncoding( "UTF-8" ); }
try { FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) { fileStream = iterator.next();
if (!fileStream.isFormField()) break; fileStream = null; }
if (fileStream == null) { return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA); }
|
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
| }
@RequestMapping("/deleteProduct") public String del(@RequestParam(value = "id")int id, HttpSession session){ productService.del(id); String imageName = id+".jpg"; File file = new File(session.getServletContext().getRealPathhttps: file.delete(); return "redirect:list"; }
@RequestMapping("/editProduct") public String editUI(@RequestParam(value = "id")int id, Model model){ Product product = productService.get(id); model.addAttribute("product",product); System.out.println(product);
List<Category> categoryList = categoryService.list(); List<User> userList = userService.list(); Category categoryByid = productService.getCategoryByCid(id); model.addAttribute("crrentCategory",categoryByid); User userById = userService.getUserByPid(id); model.addAttribute("crrentUser",userById);
model.addAttribute("categoryList",categoryList); model.addAttribute("userList",userList);
return "productmodule/product-edit"; }
@RequestMapping("/updateProduct") public String update(Product product, HttpSession session, UploadUtil upload) throws IOException { productService.update(product); if(upload!=null){
String imageName = product.getId()+".jpg";
File file = new File(session.getServletContext().getRealPathhttps:
|
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
| totalProductNumber += oi.getNumber(); } model.addAttribute("ois", ois); model.addAttribute("size", totalProductNumber);
return "forepage/foreCart"; }
@RequestMapping("/foreDelOrderItem") @ResponseBody public String foreDelOrderItem(int oiid, HttpSession session){ Customer customer = (Customer) session.getAttribute("cst"); if(customer==null){ return "noSuccess"; } orderItemService.del(oiid); return "success"; }
@RequestMapping("/foreCreateOrder") public String createOrder(Model model, String address, HttpSession session){
Order order = new Order(); Customer customer =(Customer) session.getAttribute("cst"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + RandomUtils.nextInt(10000); order.setCode(orderCode); order.setAddress(address); order.setCstid(customer.getId()); order.setStatus(0);
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=001422292105200ec
https://javayms.pages.dev?id=001422292105200ec