Java项目:基于Jsp实现网上定餐系统

简介: 项目基于JSP+SERVLET+Durid连接池进行开发实现,数据库采用MYSQL数据库,开发工具为IDEA或ECLIPSE,前端用采用BootStrap开发实现。系统采用三层架构设计,MVC设计模式。系统功能完整,页面简洁大方,维护方便,适合做毕业设计使用。具体系统功能展示如下:

 作者主页:编程指南针

简介:Java领域优质创作者、CSDN博客专家  Java项目、简历模板、学习资料、面试题库、技术互助

文末获取源码

项目编号:BS-SC-001

本项目基于JSP+SERVLET+Durid连接池进行开发实现,数据库采用MYSQL数据库,开发工具为IDEA或ECLIPSE,前端用采用BootStrap开发实现。系统采用三层架构设计,MVC设计模式。系统功能完整,页面简洁大方,维护方便,适合做毕业设计使用。

具体系统功能展示如下:

前台页面功能:

image.gif编辑

分类显示

image.gif编辑

餐品详情

image.gif编辑

添加购物车

image.gif编辑

个人订单管理

image.gif编辑

个人资料修改

image.gif编辑

系统留言

image.gif编辑

最近浏览功能

image.gif编辑

后台管理功能:

管理员登陆:  admin / admin

image.gif编辑

用户管理

image.gif编辑

分类管理

image.gif编辑

餐品管理

image.gif编辑

订单管理

image.gif编辑

留言管理

image.gif编辑

新闻管理

image.gif编辑

本系统是一款优秀的毕业设计系统,完美的实现了基于餐饮业务的网上订餐流程,功能强大,运行稳定,结构清晰,便于修改,适合做毕业设计使用。

部分核心代码:

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<ProductCategory> categories = productService
        .getProductCategories(null);
    request.setAttribute("categories", categories);
  }
  private void prepareNews(HttpServletRequest request) {
    List<News> 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));
  }
}

image.gif

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<ProductCategory> 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<ProductCategory> 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<ProductCategory> 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 {
            // 二级分类修改了名字
            productService.updateCategoryName(productCategory);
          }
        }
      }
    }
  }
  private void pupulateRequest(HttpServletRequest request,
      ProductCategory productCategory) {
    request
        .setAttribute("entityId", Long
            .toString(productCategory.getId()));
    request.setAttribute("name", productCategory.getName());
    request.setAttribute("parentId", (productCategory.getParentId()
        .equals(productCategory.getId())) ? 0 : productCategory
        .getParentId());
  }
  private void checkInputErrors(HttpServletRequest request,
      Validator validator) {
    validator.checkRequiredError(new String[] { "name" });
  }
  private void populateEntity(HttpServletRequest request,
      ProductCategory productCategory) {
    productCategory.setName(request.getParameter("name"));
  }
}

image.gif

package cn.jbit.easybuy.web;
import java.io.IOException;
import java.util.Date;
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.FacilityService;
import cn.jbit.easybuy.biz.ProductService;
import cn.jbit.easybuy.biz.impl.FacilityServiceImpl;
import cn.jbit.easybuy.biz.impl.ProductServiceImpl;
import cn.jbit.easybuy.entity.Comment;
import cn.jbit.easybuy.entity.Pager;
import cn.jbit.easybuy.entity.ProductCategory;
import cn.jbit.easybuy.util.ActionResult;
import cn.jbit.easybuy.util.Validator;
public class CommentServlet extends HttpServlet {
  private FacilityService facilityService;
  private ProductService productService;
  public void init() throws ServletException {
    this.facilityService = new FacilityServiceImpl();
    this.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 ("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) {
    Comment comment = facilityService.findCommentById(request
        .getParameter("entityId"));
    pupulateRequest(request, comment);
    return new ActionResult("guestbook-modify.jsp");
  }
  public ActionResult save(HttpServletRequest request, Validator validator,
      boolean isEdit) {
    checkInputErrors(request, validator);
    saveToDatabase(request, validator, isEdit);
    return new ActionResult("GuestBook", true);
  }
  public ActionResult delete(HttpServletRequest request, Validator validator) {
    facilityService.deleteComment(request.getParameter("entityId"));
    return new ActionResult("GuestBook", true);
  }
  public ActionResult list(HttpServletRequest request, Validator validator) {
    String page = request.getParameter("page");
    int pageNo = 1;
    if (!Validator.isEmpty(page))
      pageNo = Integer.parseInt(page);
    long rowCount = facilityService.getCommentRowCount();
    Pager pager = new Pager(rowCount, pageNo);
    List<Comment> comments = facilityService.getComments(pager);
    List<ProductCategory> categories = productService
        .getProductCategories(null);
    request.setAttribute("categories", categories);
    request.setAttribute("comments", comments);
    request.setAttribute("pager", pager);
    request.setAttribute("pageNo", pageNo);
    return new ActionResult("guestbook.jsp");
  }
  private void pupulateRequest(HttpServletRequest request, Comment comment) {
    request.setAttribute("entityId", Long.toString(comment.getId()));
    request.setAttribute("reply", comment.getReply());
    request.setAttribute("content", comment.getContent());
    request.setAttribute("nickName", comment.getNickName());
    request.setAttribute("replayTime", Validator.dateToString(comment
        .getReplyTime()));
  }
  private void saveToDatabase(HttpServletRequest request,
      Validator validator, boolean isEdit) {
    if (!validator.hasErrors()) {
      Comment comment;
      if (!isEdit) {
        comment = new Comment();
        comment.setCreateTime(new Date());
        populateEntity(request, comment);
        facilityService.saveComment(comment);
      } else {
        comment = facilityService.findCommentById(request
            .getParameter("entityId"));
        if (!Validator.isEmpty(request.getParameter("reply"))) {
          comment.setReply(request.getParameter("reply"));
          comment.setReplyTime(new Date());
        }
        facilityService.updateComment(comment);
      }
    }
  }
  private void checkInputErrors(HttpServletRequest request,
      Validator validator) {
    validator.checkRequiredError(new String[] { "content", "nickName" });
  }
  private void populateEntity(HttpServletRequest request, Comment comment) {
    comment.setContent(request.getParameter("content"));
    comment.setNickName(request.getParameter("nickName"));
  }
}

image.gif


相关文章
|
9月前
|
JavaScript Java 大数据
基于JavaWeb的销售管理系统设计系统
本系统基于Java、MySQL、Spring Boot与Vue.js技术,构建高效、可扩展的销售管理平台,实现客户、订单、数据可视化等全流程自动化管理,提升企业运营效率与决策能力。
|
9月前
|
IDE 安全 Java
Lombok 在企业级 Java 项目中的隐性成本:便利背后的取舍之道
Lombok虽能简化Java代码,但其“魔法”特性易破坏封装、影响可维护性,隐藏调试难题,且与JPA等框架存在兼容风险。企业级项目应优先考虑IDE生成、Java Records或MapStruct等更透明、稳健的替代方案,平衡开发效率与系统长期稳定性。
586 115
|
8月前
|
移动开发 监控 小程序
java家政平台源码,家政上门清洁系统源码,数据多端互通,可直接搭建使用
一款基于Java+SpringBoot+Vue+UniApp开发的家政上门系统,支持小程序、APP、H5、公众号多端互通。涵盖用户端、技工端与管理后台,支持多城市、服务分类、在线预约、微信支付、抢单派单、技能认证、钱包提现等功能,源码开源,可直接部署使用。
632 24
|
8月前
|
设计模式 消息中间件 传感器
Java 设计模式之观察者模式:构建松耦合的事件响应系统
观察者模式是Java中常用的行为型设计模式,用于构建松耦合的事件响应系统。当一个对象状态改变时,所有依赖它的观察者将自动收到通知并更新。该模式通过抽象耦合实现发布-订阅机制,广泛应用于GUI事件处理、消息通知、数据监控等场景,具有良好的可扩展性和维护性。
627 8
|
8月前
|
安全 前端开发 Java
使用Java编写UDP协议的简易群聊系统
通过这个基础框架,你可以进一步增加更多的功能,例如用户认证、消息格式化、更复杂的客户端界面等,来丰富你的群聊系统。
311 11
|
8月前
|
机器学习/深度学习 人工智能 自然语言处理
Java与生成式AI:构建内容生成与创意辅助系统
生成式AI正在重塑内容创作、软件开发和创意设计的方式。本文深入探讨如何在Java生态中构建支持文本、图像、代码等多种生成任务的创意辅助系统。我们将完整展示集成大型生成模型(如GPT、Stable Diffusion)、处理生成任务队列、优化生成结果以及构建企业级生成式AI应用的全流程,为Java开发者提供构建下一代创意辅助系统的完整技术方案。
414 10
|
8月前
|
人工智能 监控 Java
Java与AI智能体:构建自主决策与工具调用的智能系统
随着AI智能体技术的快速发展,构建能够自主理解任务、制定计划并执行复杂操作的智能系统已成为新的技术前沿。本文深入探讨如何在Java生态中构建具备工具调用、记忆管理和自主决策能力的AI智能体系统。我们将完整展示从智能体架构设计、工具生态系统、记忆机制到多智能体协作的全流程,为Java开发者提供构建下一代自主智能系统的完整技术方案。
1059 4
|
8月前
|
机器学习/深度学习 分布式计算 Java
Java与图神经网络:构建企业级知识图谱与智能推理系统
图神经网络(GNN)作为处理非欧几里得数据的前沿技术,正成为企业知识管理和智能推理的核心引擎。本文深入探讨如何在Java生态中构建基于GNN的知识图谱系统,涵盖从图数据建模、GNN模型集成、分布式图计算到实时推理的全流程。通过具体的代码实现和架构设计,展示如何将先进的图神经网络技术融入传统Java企业应用,为构建下一代智能决策系统提供完整解决方案。
683 0
|
9月前
|
存储 小程序 Java
热门小程序源码合集:微信抖音小程序源码支持PHP/Java/uni-app完整项目实践指南
小程序已成为企业获客与开发者创业的重要载体。本文详解PHP、Java、uni-app三大技术栈在电商、工具、服务类小程序中的源码应用,提供从开发到部署的全流程指南,并分享选型避坑与商业化落地策略,助力开发者高效构建稳定可扩展项目。
|
Java 容器
【学习笔记】Jsp与Servlet技术
【学习笔记】Jsp与Servlet技术
475 0