基于Java SSM实现在线点餐系统

 更新时间:2022年02月10日 11:49:59   作者:编程指南针  
本项目基于Java SSM框架实现在线点餐系统,主要实现系统的在线点餐功能。文中的示例代码讲解详细,感兴趣的可以跟随小编一起学习一下

介绍

项目编号:BS-PT-022

本项目基于SSM框架实现在线点餐系统,主要实现系统的在线点餐功能。

开发工具:IDEA/ECLIPSE

数据库:MYSQL5.7

后台技术:SSM

前台技术:CSS,JS,JSP

应用服务器:TOMCAT8.5

效果图

下面展示一下系统功能:

首页

我的餐车

订单

用户中心

会员登陆

会员注册

后台登陆

菜单管理

菜单类别管理

公告信息管理

订单管理

信息修改

核心代码

package com.example.meal_ordering_system.controller;
 
import com.example.meal_ordering_system.entity.Admin;
import com.example.meal_ordering_system.entity.Menus;
import com.example.meal_ordering_system.entity.Types;
import com.example.meal_ordering_system.service.AdminService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
 
/**
 * (Admin)表控制层
 *
 * @author znz
 * @since 2021-02-04 12:51:19
 */
@Controller
@RequestMapping("admin")
public class AdminController {
    /**
     * 服务对象
     */
    //自动注入业务层的AdminService类
    @Autowired
    @Qualifier("adminService")
    private AdminService adminService;
 
    //修改管理员信息
    @RequestMapping("update")
    public String update(Admin admin) {
        adminService.update(admin);
        return "/admin/menus";
    }
 
 
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String toLogin(){
        return  "/admin/index";
    }
 
    //login业务的访问位置为/admin/login
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(Admin admin, HttpServletRequest request,HttpSession session){
        //调用login方法来验证是否是注册用户
        boolean loginType = adminService.login(admin.getName(),admin.getPwd());
        if(loginType){
            //如果验证通过,则将用户信息传到前台
            request.setAttribute("admin",admin);
            session.setAttribute("admin_session",admin);
            //并跳转到success.jsp页面
            return "/admin/main";
        }else{
            //若不对,则返回
            request.setAttribute("message","用户名密码错误");
            return "/admin/index";
        }
    }
 
    //登出,地址/admin/logout
    @RequestMapping("logout")
    public String logout(HttpSession session){
        //清除session
        session.removeAttribute("admin_session");
        //重定向到登录页面的跳转方法
        return "/admin/index";
    }
 
 
 
}
package com.example.meal_ordering_system.controller;
 
import com.example.meal_ordering_system.entity.Users;
import com.example.meal_ordering_system.service.UsersService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Random;
import java.util.UUID;
 
/**
 * (Users)表控制层
 *
 * @author znz
 * @since 2021-02-04 12:51:21
 */
@Controller("usersController")
@RequestMapping("users")
@Scope("prototype")
public class UsersController {
    /**
     * 服务对象
     */
    @Autowired
    @Qualifier("usersService")
    private UsersService usersService;
 
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping ("queryById")
    public Users queryById(Integer id) {
        return this.usersService.queryById(id);
    }
 
 
    /**
     * 登录方法
     * @param user
     * @param request
     * @return
     */
    @RequestMapping("login")
    public String login(Users user, HttpServletRequest request){
        boolean loginType=usersService.login(user.getName(), user.getPwd());
        HttpSession session=request.getSession();
        if(loginType){
            session.setAttribute("user_session",usersService.queryById(usersService.queryByname(user.getName())));
            return "redirect:/menus/qiantai/allMenus";
        }else{
            session.setAttribute("message","用户名密码错误");
            return "qiantai/userLoginFail";
        }
    }
    //登出,地址/users/logout
    @RequestMapping("logout")
    public String logout(String type,HttpSession session){
        //清除session
        session.removeAttribute("user_session");
        if(type!=null&&type.equals("qiantai")){
            return "redirect:/menus/qiantai/allMenus";
        }else {
            //重定向到登录页面的跳转方法
            return "/admin/index";
        }
    }
 
    @RequestMapping("insert")
    public String insert(@Param("name") String name,@Param("pwd") String pwd,@Param("realname") String realname,@Param("sex") String sex,@Param("age") Integer age,@Param("card") String card,@Param("address") String address,@Param("Phone") String phone,@Param("email")String email,@Param("code")String code,@Param("type")Integer type){
        Users user=new Users(name,pwd,realname,sex,age,card,address,phone,email,code,type);
        usersService.insert(user);
        return "redirect:../public/qiantai/login.jsp";
    }
 
 
    @RequestMapping("update")
    public String update(HttpSession session,@Param("id")Integer id,@Param("name") String name,@Param("pwd") String pwd,@Param("realname") String realname,@Param("sex") String sex,@Param("age") Integer age,@Param("card") String card,@Param("address") String address,@Param("Phone") String phone,@Param("email")String email,@Param("code")String code,@Param("type")Integer type){
        Users user=new Users(id,name,pwd,realname,sex,age,card,address,phone,email,code,type);
        usersService.update(user);
        session.removeAttribute("user_session");
        return "redirect:/users/login";
    }
}
package com.example.meal_ordering_system.controller;
 
import com.example.meal_ordering_system.entity.*;
import com.example.meal_ordering_system.service.MenusService;
import com.example.meal_ordering_system.service.OrdersService;
import com.example.meal_ordering_system.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
 
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * (Orders)表控制层
 *
 * @author znz
 * @since 2021-02-04 12:51:20
 */
@Controller
@RequestMapping("orders")
public class OrdersController {
    /**
     * 服务对象
     */
    @Autowired
    @Qualifier("ordersService")
    private OrdersService ordersService;
 
    @Autowired
    @Qualifier("menusService")
    private MenusService menusService;
 
    @Autowired
    @Qualifier("usersService")
      private UsersService usersService;
 
    //获取全部订单信息
    @RequestMapping("ordergetall")
    public String ordergetall( HttpServletRequest request) {
        //传给前端
        Pages page1=null;
        //总页面
        Integer totalCount=null;
 
        //当前页面
        String currentpages="1";
 
        //获取上一页还是下一页标识
        String s="";
 
        //数据库操作页面
        String pagess="1";
 
        //前端页面总数
        Integer allpage=null;
 
        //如果不为空则获取currentpage
        if(request.getParameter("currentpage")!=null){
            currentpages=request.getParameter("currentpage");
            totalCount= ordersService.pageCount();
            allpage=totalCount/5;
            if(totalCount%5!=0){
                allpage++;
            }
            if(Integer.parseInt(currentpages)<=0){
                currentpages="1";
            }
            if(Integer.parseInt(currentpages)>allpage){
                currentpages=""+allpage;
            }
 
 
            //设置pagess的值
            if(request.getParameter("s")!=null){
                s=request.getParameter("s");
                if(s.equals("up")){
                    pagess=""+(Integer.parseInt(currentpages)-4);
                }else if(s.equals("down")){
                    pagess=""+((Integer.parseInt(currentpages)-1)*5-1);
                }else if (s.equals("first")){
                    pagess="0";
                }else if(s.equals("last")){
                    pagess=""+(totalCount-(totalCount%5)-1);
                }else {
                    System.out.println("错误");
                }
            }
 
            page1=new Pages(currentpages,allpage);
            request.setAttribute("pages",page1);
 
        }else{
            totalCount= ordersService.pageCount();
            allpage=totalCount/5;
            if(ordersService.pageCount()%5!=0){
                allpage++;
            }
            page1=new Pages("1", allpage);
 
            request.setAttribute("pages",page1);
        }
 
        //判断操作数据库页面是否突破限制
        if(Integer.parseInt(pagess)<=0){
            pagess="0";
        }
        if(Integer.parseInt(pagess)>totalCount){
            pagess=""+(totalCount-(totalCount%5)-1);
        }
 
 
        List<Orders> list= ordersService.pageList(Integer.parseInt(pagess),5);
        request.setAttribute("list",list);
 
        System.out.println("pagess="+pagess);
        System.out.println("currentpages="+currentpages);
 
        return "/admin/order";
    }
 
    //确认订单 确认则将deliverys设置为一否则删除
    @RequestMapping("OrderComfirm")
    public String OrderComfirm( HttpServletRequest request){
        int id=Integer.parseInt(request.getParameter("id"));
        String reqtype=request.getParameter("reqtype");
        if(reqtype.equals("delivery")){
            ordersService.updatedeliveryById(id);
        }else if(reqtype.equals("del")){
            ordersService.deleteById(id);
        }else{
            System.out.println("错误");
        }
 
        return "redirect:/orders/ordergetall";
    }
 
 
    @RequestMapping("order_search")
    public String order_search( HttpServletRequest request) {
        return "/admin/order_search";
    }
 
 
 
    @RequestMapping("ordergetallbydelivery")
    public  String ordergetallbydelivery(HttpServletRequest request){
        String delivery=request.getParameter("delivery");
        Integer d=Integer.parseInt(delivery);
        List<Orders> list=ordersService.pageListByDelivery(d);
        HttpSession session=request.getSession();
        session.setAttribute("ordersearch", list);
        return "/qiantai/order";
    }
 
    @RequestMapping(value="order_qiantai",method = RequestMethod.POST)
    public String  order_qiantai( HttpServletRequest request) throws UnsupportedEncodingException {
        List<Orders> list=null;
        HttpSession session=request.getSession();
        request.setCharacterEncoding("utf-8");
        Integer id=null;
        String menuname=null;
        String day1=null;
        if(request.getParameter("menuname")!=null&&(!request.getParameter("menuname").equals(""))){
            menuname=request.getParameter("menuname");
            list=ordersService.pageListByMenue(menuname);
        }else if(request.getParameter("date")!=null&&(!request.getParameter("date").equals(""))){
            day1=request.getParameter("date");
            Integer a=Integer.parseInt(day1.substring(9,10));
            String aa=""+(a+1);
            StringBuilder day=new StringBuilder(day1);
            day.replace(9,10,aa);
            String day2=day.toString();
            list=ordersService.pageListByDate(day1,day2);
        }else {
            System.out.println("未提交");
        }
 
 
        session.setAttribute("ordersearch", list);
        System.out.println(id);
        System.out.println(menuname);
        System.out.println(day1);
 
        return "/qiantai/order";
 
 
    }
 
 
    @RequestMapping(value="order_searchs",method = RequestMethod.POST)
    public String order_searchs( HttpServletRequest request) throws UnsupportedEncodingException {
 
        List<Orders> list=null;
        HttpSession session=request.getSession();
        request.setCharacterEncoding("utf-8");
        Integer id=null;
        String menuname=null;
        String day1=null;
        if(request.getParameter("userid")!=null&&(!request.getParameter("userid").equals(""))){
            id=Integer.parseInt(request.getParameter("userid"));
            list=ordersService.pageListByID(id);
        }else if(request.getParameter("menuname")!=null&&(!request.getParameter("menuname").equals(""))){
            menuname=request.getParameter("menuname");
            list=ordersService.pageListByMenue(menuname);
        }else if(request.getParameter("date")!=null&&(!request.getParameter("date").equals(""))){
            day1=request.getParameter("date");
            Integer a=Integer.parseInt(day1.substring(9,10));
            String aa=""+(a+1);
            StringBuilder day=new StringBuilder(day1);
            day.replace(9,10,aa);
            String day2=day.toString();
            list=ordersService.pageListByDate(day1,day2);
        }else {
            System.out.println("未提交");
        }
 
 
        session.setAttribute("ordersearch", list);
        System.out.println(id);
        System.out.println(menuname);
        System.out.println(day1);
 
        return "/admin/order_search";
    }
 
    //跳转到statistic页面
    @RequestMapping("order_statistic")
    public String order_statistic( HttpServletRequest request) throws UnsupportedEncodingException {
        List<Orders> list=null;
        HttpSession session=request.getSession();
        request.setCharacterEncoding("utf-8");
 
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        String day1=formatter.format(date);
        Integer a=Integer.parseInt(day1.substring(9,10));
        String aa=""+(a+1);
        StringBuilder day=new StringBuilder(day1);
        day.replace(9,10,aa);
        String day2=day.toString();
 
        System.out.println(a);
        System.out.println(day1);
        System.out.println(day2);
        list=ordersService.pageListByDate(day1,day2);
 
        session.setAttribute("orderstatistic", list);
 
        return "/admin/order_statistic";
 
    }
 
    @RequestMapping("orderqiantai")
    public String orderqiantai( HttpServletRequest request){
        return "/qiantai/order";
    }
 
 
    //放入购物车
    @RequestMapping("order_addshoppingcar")
    public String order_addshoppingcar(HttpServletRequest request){
        HttpSession session=request.getSession();
 
        String menuId = request.getParameter("menuId");
        Integer id=Integer.parseInt(menuId);
        Integer sum=(Integer) session.getAttribute("sum");
        if(sum==null){
            sum=1;
            session.setAttribute("sum",sum);
        }
        Menus menus = menusService.queryById(id);
        String name=menus.getName();
        float price=menus.getPrice1();
 
        ShoppingCart shoppingCart1=new ShoppingCart(id,name,price,sum);
        List<ShoppingCart> shoppingCarts=new ArrayList();
        if(session.getAttribute("shoppingcar")!=null){
            shoppingCarts=(List<ShoppingCart>)session.getAttribute("shoppingcar");
            for (ShoppingCart shoppingCart:shoppingCarts) {
                if(name.equals(shoppingCart.getName())){
                    sum=shoppingCart.getSums()+1;
                    shoppingCarts.remove(shoppingCart);
                    break;
                }
            }
            shoppingCart1=new ShoppingCart(id,name,price,sum);
            shoppingCarts.add(shoppingCart1);
            session.setAttribute("shoppingcar",shoppingCarts);
        }else{
            shoppingCart1=new ShoppingCart(id,name,price,sum);
            shoppingCarts.add(shoppingCart1);
            session.setAttribute("shoppingcar",shoppingCarts);
        }
        return "redirect:/menus/qiantai/allMenus";
    }
 
 
    //购物车单个取消
    @RequestMapping("order_shoppingcardel")
    public String order_shoppingcardel(HttpServletRequest request){
        HttpSession session=request.getSession();
        List<ShoppingCart> shoppingCarts=(List<ShoppingCart>)session.getAttribute("shoppingcar");
        Integer id=Integer.parseInt(request.getParameter("del"));
        Integer i=0;
        for (ShoppingCart shoppingCart:shoppingCarts) {
            if(i.equals(id)){
                shoppingCarts.remove(shoppingCart);
                break;
            }
            i++;
        }
 
        return "redirect:/menus/qiantai/allMenus";
    }
    @RequestMapping("order_addshoppingcartoOrder")
 
    //提交或取消订单
    public String order_addshoppingcartoOrder(HttpServletRequest request) {
        HttpSession session=request.getSession();
        List<ShoppingCart> shoppingCarts=(List<ShoppingCart>)session.getAttribute("shoppingcar");
        if(session.getAttribute("user_session")!=null) {
            Users user = (Users) session.getAttribute("user_session");
            Integer userid = usersService.queryByname(user.getName());
            Integer delivery = 0;
            String remove = request.getParameter("remove");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date(System.currentTimeMillis());
            String day = formatter.format(date);
            Integer id = null;
            if (shoppingCarts != null) {
                for (ShoppingCart shoppingCart : shoppingCarts) {
                    Integer sums = shoppingCart.getSums();
                    Integer menuid = shoppingCart.getId();
                    Orders orders = new Orders(id, userid, menuid, sums, day, delivery);
                    ordersService.insert(orders);
                }
                session.removeAttribute("shoppingcar");
            }
 
            if(remove!=null) {
                if (remove.equals("1")) {
                    session.removeAttribute("shoppingcar");
                }
            }
        }else{
            return "redirect:../public/qiantai/login.jsp";
        }
        return "redirect:/menus/qiantai/allMenus";
    }
 
}

以上就是基于Java SSM实现在线点餐系统的详细内容,更多关于Java SSM在线点餐系统的资料请关注脚本之家其它相关文章!

相关文章

  • IDEA中的.iml文件和.idea文件的作用及意义

    IDEA中的.iml文件和.idea文件的作用及意义

    iml是 项目标识文件,每一个模块都有一个iml文件,存储模块的相关信息,跟eclipse的project文件是一样的功能,这篇文章主要介绍了IDEA中的.iml文件和.idea文件的作用,需要的朋友可以参考下
    2023-09-09
  • springboot中请求地址转发的两种方案

    springboot中请求地址转发的两种方案

    在开发过程中,我们经常需要将请求从一个服务转发到另一个服务,以实现不同服务之间的协作,本文主要介绍了springboot中请求地址转发的两种方案,感兴趣的可以了解一下
    2023-11-11
  • JAVA8之函数式编程Function接口用法

    JAVA8之函数式编程Function接口用法

    这篇文章主要介绍了JAVA8之函数式编程Function接口用法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-12-12
  • 详解Java的闭包

    详解Java的闭包

    这篇文章主要介绍了详解Java的闭包,作者从Lambda和默认方法等重要特性深入讲解,极力推荐!需要的朋友可以参考下
    2015-07-07
  • Java实现UTF-8编码与解码方式

    Java实现UTF-8编码与解码方式

    这篇文章主要介绍了Java实现UTF-8编码与解码方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-04-04
  • Java开发Oracle数据库连接JDBC Thin Driver 的三种方法

    Java开发Oracle数据库连接JDBC Thin Driver 的三种方法

    这篇文章主要介绍了Java开发Oracle数据库连接JDBC Thin Driver 的三种方法,需要的朋友可以参考下
    2015-12-12
  • 讲解Java编程中finally语句的基本使用方法

    讲解Java编程中finally语句的基本使用方法

    这篇文章主要介绍了讲解Java编程中finally语句的基本使用方法,finally在异常处理中的使用时Java入门学习中的基础知识,需要的朋友可以参考下
    2015-11-11
  • 关于idea2022.2 闪退的问题

    关于idea2022.2 闪退的问题

    最近更新了idea2022.2版本,这是一个比较大的软件版本更迭,下面小编给大家介绍下idea2022.2 闪退的问题及解决方法,需要的朋友可以参考下
    2022-08-08
  • Java 判断字符串a和b是否互为旋转词

    Java 判断字符串a和b是否互为旋转词

    本篇文章主要介绍了判断字符串a和b是否互为旋转词的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧
    2017-05-05
  • SSM框架整合之Spring+SpringMVC+MyBatis实践步骤

    SSM框架整合之Spring+SpringMVC+MyBatis实践步骤

    大家都知道Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架,本文主要介绍三大框架的整合包含spring和mybatis的配置文件,还有spring-mvc的配置文件的详细介绍,通过项目实践步骤给大家详细介绍,感兴趣的朋友一起看看吧
    2021-06-06

最新评论