具体系统功能展示如下:
前台页面功能:
分类显示
餐品详情
添加购物车
个人订单管理
个人资料修改
系统留言
最近浏览功能
后台管理功能:
管理员登陆: admin / admin
用户管理
分类管理
餐品管理
订单管理
留言管理
新闻管理
本系统是一款优秀的毕业设计系统,完美的实现了基于餐饮业务的网上订餐流程,功能强大,运行稳定,结构清晰,便于修改,适合做毕业设计使用。
部分核心代码:
package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import cn.jbit.easybuy.biz.FacilityService;
import cn.jbit.easybuy.biz.OrderService;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.FacilityServiceImpl;
import cn.jbit.easybuy.biz.impl.OrderServiceImpl;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.News;
import cn.jbit.easybuy.entity.Pager;
import cn.jbit.easybuy.entity.Product;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.entity.ShoppingCart;
import cn.jbit.easybuy.entity.User;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CartServlet extends HttpServlet {
protected Map<String, ActionResult> viewMapping = new HashMap<String, ActionResult>();
private ProductService productService;
private FacilityService facilityService;
private OrderService orderService;
public void init() throws ServletException {
productService = new ProductServiceImpl();
facilityService = new FacilityServiceImpl();
orderService = new OrderServiceImpl();
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding(“utf-8”);
createViewMapping();
String actionIndicator = req.getParameter(“action”);
String result = “”;
if (actionIndicator == null)
actionIndicator = “list”;
if (“list”.endsWith(actionIndicator)) {
result = list(req);
} else if (“add”.endsWith(actionIndicator)) {
result = add(req);
} else if (“mod”.endsWith(actionIndicator)) {
result = mod(req);
} else if (“remove”.endsWith(actionIndicator)) {
result = remove(req);
} else if (“pay”.endsWith(actionIndicator)) {
result = pay(req);
}
toView(req, resp, result);
}
private String pay(HttpServletRequest request) {
ShoppingCart cart = getCartFromSession(request);
User user = getUserFromSession(request);
if(user==null)
return “login”;
orderService.payShoppingCart(cart, user);
removeCartFromSession(request);
return “paySuccess”;
}
private void removeCartFromSession(HttpServletRequest request) {
request.getSession().removeAttribute(“cart”);
}
private User getUserFromSession(HttpServletRequest request) {
HttpSession session = request.getSession();
return (User) session.getAttribute(“loginUser”);
}
private String add(HttpServletRequest request) {
String id = request.getParameter(“entityId”);
String quantityStr = request.getParameter(“quantity”);
long quantity = 1;
if (!Validator.isEmpty(quantityStr))
quantity = Long.parseLong(quantityStr);
Product product = productService.findById(id);
ShoppingCart cart = getCartFromSession(request);
cart.addItem(product, quantity);
return “addSuccess”;
}
private String mod(HttpServletRequest request) {
String id = request.getParameter(“entityId”);
String quantityStr = request.getParameter(“quantity”);
long quantity = 1;
if (!Validator.isEmpty(quantityStr))
quantity = Long.parseLong(quantityStr);
String indexStr = request.getParameter(“index”);
ShoppingCart cart = getCartFromSession(request);
cart.modifyQuantity(Integer.parseInt(indexStr), quantity);
return “modSuccess”;
}
private String remove(HttpServletRequest request) {
String id = request.getParameter(“entityId”);
String quantityStr = request.getParameter(“quantity”);
long quantity = 1;
if (!Validator.isEmpty(quantityStr))
quantity = Long.parseLong(quantityStr);
String indexStr = request.getParameter(“index”);
ShoppingCart cart = getCartFromSession(request);
cart.getItems().remove(Integer.parseInt(indexStr));
return “removeSuccess”;
}
private ShoppingCart getCartFromSession(HttpServletRequest request) {
HttpSession session = request.getSession();
ShoppingCart cart = (ShoppingCart) session.getAttribute(“cart”);
if (cart == null) {
cart = new ShoppingCart();
session.setAttribute(“cart”, cart);
}
//取出当前用户的订单列表
return cart;
}
private String list(HttpServletRequest request) {
getCartFromSession(request);
return “listSuccess”;
}
private void prepareCategories(HttpServletRequest request) {
List categories = productService
.getProductCategories(null);
request.setAttribute(“categories”, categories);
}
private void prepareNews(HttpServletRequest request) {
List allNews = facilityService.getAllNews(new Pager(10, 1));
request.setAttribute(“allNews”, allNews);
}
protected void createViewMapping() {
this.addMapping(“listSuccess”, “shopping.jsp”);
this.addMapping(“paySuccess”, “shopping-result.jsp”);
this.addMapping(“addSuccess”, “Cart”, true);
this.addMapping(“removeSuccess”, “Cart”, true);
this.addMapping(“modSuccess”, “Cart”, true);
this.addMapping(“login”, “login.jsp”);
}
private void toView(HttpServletRequest req, HttpServletResponse resp,
String result) throws IOException, ServletException {
ActionResult dest = this.viewMapping.get(result);
if (dest.isRedirect()) {
resp.sendRedirect(dest.getViewName());
} else {
req.getRequestDispatcher(dest.getViewName()).forward(req, resp);
}
}
protected void addMapping(String viewName, String url) {
this.viewMapping.put(viewName, new ActionResult(url));
}
protected void addMapping(String viewName, String url, boolean isDirect) {
this.viewMapping.put(viewName, new ActionResult(url, isDirect));
}
}
package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CategoryServlet extends HttpServlet {
private ProductService productService;
public void init() throws ServletException {
productService = new ProductServiceImpl();
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding(“utf-8”);
String actionIndicator = req.getParameter(“action”);
ActionResult result = new ActionResult(“error”);
Validator validator = new Validator(Validator.toSingleParameters(req));
if (actionIndicator == null)
actionIndicator = “list”;
if (“read”.endsWith(actionIndicator)) {
result = read(req, validator);
} else if (“list”.endsWith(actionIndicator)) {
result = list(req, validator);
} else if (“create”.endsWith(actionIndicator)) {
result = create(req, validator);
} else if (“delete”.endsWith(actionIndicator)) {
result = delete(req, validator);
} else if (“save”.endsWith(actionIndicator)) {
boolean isEdit = true;
String editIndicator = req.getParameter(“entityId”);
if (Validator.isEmpty(editIndicator))
isEdit = false;
result = save(req, validator, isEdit);
}
if (!validator.hasErrors() && result.isRedirect()) {
resp.sendRedirect(result.getViewName());
} else {
req.setAttribute(“errors”, validator.getErrors());
req.getRequestDispatcher(result.getViewName()).forward(req, resp);
}
}
public ActionResult read(HttpServletRequest request, Validator validator) {
ProductCategory category = productService.findCategoryById(request
.getParameter(“entityId”));
pupulateRequest(request, category);
List categories = productService.getRootCategories();
request.setAttribute(“categories”, categories);
return new ActionResult(“productClass-modify.jsp”);
}
public ActionResult save(HttpServletRequest request, Validator validator,
boolean isEdit) {
String entityId = request.getParameter(“entityId”);
checkInputErrors(request, validator);
saveToDatabase(request, validator, isEdit);
return new ActionResult(“Category”, true);
}
public ActionResult create(HttpServletRequest request, Validator validator) {
List categories = productService.getRootCategories();
request.setAttribute(“categories”, categories);
request.setAttribute(“parentId”, 0);
return new ActionResult(“productClass-modify.jsp”);
}
public ActionResult delete(HttpServletRequest request, Validator validator) {
productService.deleteCategory(request.getParameter(“entityId”));
return new ActionResult(“Category”, true);
}
public ActionResult list(HttpServletRequest request, Validator validator) {
List categories = productService
.getProductCategories(null);
request.setAttribute(“categories”, categories);
return new ActionResult(“productClass.jsp”);
}
private void saveToDatabase(HttpServletRequest request,
Validator validator, boolean isEdit) {
if (!validator.hasErrors()) {
ProductCategory productCategory;
if (!isEdit) {
productCategory = new ProductCategory();
populateEntity(request, productCategory);
productCategory.setParentId(Long.parseLong(request
.getParameter(“parentId”)));
productService.saveCategory(productCategory);
} else {
productCategory = productService.findCategoryById(request
.getParameter(“entityId”));
Long parentId = Long
.parseLong(request.getParameter(“parentId”));
populateEntity(request, productCategory);
if (parentId == 0) {
if (productCategory.getId().equals(
productCategory.getParentId())) {
// 说明是一级分类,父分类不能修改,只能改名字
productService.updateCategoryName(productCategory);
} else {
// 二级分类修改为一级分类了,需要额外更新:
// Product原先属于该二级分类的,全部更新一级为它,二级为空
productCategory.setParentId(productCategory.getId());
productService.updateCategory(productCategory,
“Level2To1”);
}
} else {
if (!parentId.equals(productCategory.getParentId())) {
// 二级分类修改了父分类,需要额外更新:
// Product原先属于该二级分类的,全部更新一级为新的父分类
productCategory.setParentId(parentId);
productService.updateCategory(productCategory,
“ModifyParent”);
} else {
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
了父分类,需要额外更新:
// Product原先属于该二级分类的,全部更新一级为新的父分类
productCategory.setParentId(parentId);
productService.updateCategory(productCategory,
“ModifyParent”);
} else {
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-A3ZBiNv4-1715821422960)]
[外链图片转存中…(img-5Tzzbqwv-1715821422961)]
[外链图片转存中…(img-rTmkyIRT-1715821422961)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!