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


相关文章
|
2天前
|
SQL Java 数据库连接
从理论到实践:Hibernate与JPA在Java项目中的实际应用
本文介绍了Java持久层框架Hibernate和JPA的基本概念及其在具体项目中的应用。通过一个在线书店系统的实例,展示了如何使用@Entity注解定义实体类、通过Spring Data JPA定义仓库接口、在服务层调用方法进行数据库操作,以及使用JPQL编写自定义查询和管理事务。这些技术不仅简化了数据库操作,还显著提升了开发效率。
12 3
|
6天前
|
运维 自然语言处理 供应链
Java云HIS医院管理系统源码 病案管理、医保业务、门诊、住院、电子病历编辑器
通过门诊的申请,或者直接住院登记,通过”护士工作站“分配患者,完成后,进入医生患者列表,医生对应开具”长期医嘱“和”临时医嘱“,并在电子病历中,记录病情。病人出院时,停止长期医嘱,开具出院医嘱。进入出院审核,审核医嘱与住院通过后,病人结清缴费,完成出院。
27 3
|
5天前
|
前端开发 Java 数据库
如何实现一个项目,小白做项目-java
本教程涵盖了从数据库到AJAX的多个知识点,并详细介绍了项目实现过程,包括静态页面分析、数据库创建、项目结构搭建、JSP转换及各层代码编写。最后,通过通用分页和优化Servlet来提升代码质量。
17 1
|
10天前
|
Java 数据库连接 数据库
深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能
在Java应用开发中,数据库操作常成为性能瓶颈。本文通过问题解答形式,深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能。文章介绍了连接池的优势、选择和使用方法,以及优化配置的技巧。
14 1
|
12天前
|
JavaScript Java 项目管理
Java毕设学习 基于SpringBoot + Vue 的医院管理系统 持续给大家寻找Java毕设学习项目(附源码)
基于SpringBoot + Vue的医院管理系统,涵盖医院、患者、挂号、药物、检查、病床、排班管理和数据分析等功能。开发工具为IDEA和HBuilder X,环境需配置jdk8、Node.js14、MySQL8。文末提供源码下载链接。
|
15天前
|
移动开发 前端开发 JavaScript
java家政系统成品源码的关键特点和技术应用
家政系统成品源码是已开发完成的家政服务管理软件,支持用户注册、登录、管理个人资料,家政人员信息管理,服务项目分类,订单与预约管理,支付集成,评价与反馈,地图定位等功能。适用于各种规模的家政服务公司,采用uniapp、SpringBoot、MySQL等技术栈,确保高效管理和优质用户体验。
|
17天前
|
XML JSON 监控
告别简陋:Java日志系统的最佳实践
【10月更文挑战第19天】 在Java开发中,`System.out.println()` 是最基本的输出方法,但它在实际项目中往往被认为是不专业和不足够的。本文将探讨为什么在现代Java应用中应该避免使用 `System.out.println()`,并介绍几种更先进的日志解决方案。
42 1
|
21天前
|
Java 关系型数据库 API
介绍一款Java开发的企业接口管理系统和开放平台
YesApi接口管理平台Java版,基于Spring Boot、Vue.js等技术,提供API接口的快速研发、管理、开放及收费等功能,支持多数据库、Docker部署,适用于企业级PaaS和SaaS平台的二次开发与搭建。
|
11天前
|
安全 Java
java 中 i++ 到底是否线程安全?
本文通过实例探讨了 `i++` 在多线程环境下的线程安全性问题。首先,使用 100 个线程分别执行 10000 次 `i++` 操作,发现最终结果小于预期的 1000000,证明 `i++` 是线程不安全的。接着,介绍了两种解决方法:使用 `synchronized` 关键字加锁和使用 `AtomicInteger` 类。其中,`AtomicInteger` 通过 `CAS` 操作实现了高效的线程安全。最后,通过分析字节码和源码,解释了 `i++` 为何线程不安全以及 `AtomicInteger` 如何保证线程安全。
java 中 i++ 到底是否线程安全?
|
1天前
|
存储 安全 Java
Java多线程编程的艺术:从基础到实践####
本文深入探讨了Java多线程编程的核心概念、应用场景及其实现方式,旨在帮助开发者理解并掌握多线程编程的基本技能。文章首先概述了多线程的重要性和常见挑战,随后详细介绍了Java中创建和管理线程的两种主要方式:继承Thread类与实现Runnable接口。通过实例代码,本文展示了如何正确启动、运行及同步线程,以及如何处理线程间的通信与协作问题。最后,文章总结了多线程编程的最佳实践,为读者在实际项目中应用多线程技术提供了宝贵的参考。 ####
下一篇
无影云桌面