一、系统分为两端
(1)网上订餐前端
(2)网上订餐管理端
系统开发的技术(Javaweb技术、Spring、jsp页面、MVC模式)以及使用的工具(Eclipse集成开发工具、MySQL数据库)等基础知识;
二、系统主要功能
用户:
① 用户注册
② 用户登录
③ 菜品浏览
④ 菜品订购
⑤ 菜品查询
⑥ 订单修改
⑦ 修改密码
⑧ 修改个人信息
管理员:
① 用户信息管理
② 销售订单管理
③ 系统用户管理
④ 菜单管理
⑤ 菜单类别管理
⑥ 公告发布管理
三、系统截图
四、主要功能代码
(1)管理员登录
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 makejava
* @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.service;
import com.example.meal_ordering_system.entity.Admin;
import com.example.meal_ordering_system.entity.Types;
import java.util.List;
/**
* (Admin)表服务接口
*
* @author makejava
* @since 2021-02-04 12:49:13
*/
public interface AdminService {
/**
* 通过ID查询单条数据
*
* @param name 主键
* @return 实例对象
*/
Admin queryByName(String name) ;
boolean login(String name,String pwd);
/**
* 查询多条数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<Admin> queryAllByLimit(int offset, int limit);
/**
* 新增数据
*
* @param admin 实例对象
* @return 实例对象
*/
Admin insert(Admin admin);
int update(Admin admin);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
boolean deleteById(Integer id);
}
package com.example.meal_ordering_system.service.impl;
import com.example.meal_ordering_system.dao.AdminDao;
import com.example.meal_ordering_system.entity.Admin;
import com.example.meal_ordering_system.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* (Admin)表服务实现类
*
* @author makejava
* @since 2021-02-04 12:49:13
*/
@Service("adminService")
public class AdminServiceImpl implements AdminService {
@Resource
private AdminDao adminDao;
/**
* 通过ID查询单条数据
*
* @param name 用户名
* @return 实例对象
*/
@Override
public Admin queryByName(String name) {
return this.adminDao.queryByName(name);
}
/**
* 查询多条数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
@Override
public List<Admin> queryAllByLimit(int offset, int limit) {
return this.adminDao.queryAllByLimit(offset, limit);
}
/**
* 新增数据
*
* @param admin 实例对象
* @return 实例对象
*/
@Override
public Admin insert(Admin admin) {
this.adminDao.insert(admin);
return admin;
}
@Override
public int update(Admin admin){
this.adminDao.update(admin);
return 0;
};
//登录方法的实现,从jsp页面获取username与password
public boolean login(String name, String pwd) {
Admin admin = adminDao.queryByName(name);
if (admin != null) {
if (admin.getName().equals(name) && admin.getPwd().equals(pwd))
return true;
}
return false;
}
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
@Override
public boolean deleteById(Integer id) {
return this.adminDao.deleteById(id) > 0;
}
}
package com.example.meal_ordering_system.dao;
import com.example.meal_ordering_system.entity.Admin;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* (Admin)表数据库访问层
*
* @author makejava
* @since 2021-02-04 12:44:06
*/
public interface AdminDao {
/**
* 通过ID查询单条数据
*
* @param name 用户名
* @return 实例对象
*/
Admin queryByName(String name);
/**
* 查询指定行数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<Admin> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
/**
* 通过实体作为筛选条件查询
*
* @param admin 实例对象
* @return 对象列表
*/
List<Admin> queryAll(Admin admin);
/**
* 新增数据
*
* @param admin 实例对象
* @return 影响行数
*/
int insert(Admin admin);
/**
* 修改数据
*
* @param admin 实例对象
* @return 影响行数
*/
int update(Admin admin);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Integer id);
}
package com.example.meal_ordering_system.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class Admin {
private Integer id;
private String name;
private String pwd;
private String authority;
public Admin() {
}
public Admin(Integer id, String name, String pwd, String authority) {
this.id = id;
this.name = name;
this.pwd = pwd;
this.authority = authority;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getAuthority() {
return authority;
}
public void setAuthority(String authority) {
this.authority = authority;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.meal_ordering_system.dao.AdminDao">
<resultMap type="com.example.meal_ordering_system.entity.Admin" id="AdminMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="pwd" column="pwd" jdbcType="VARCHAR"/>
<result property="authority" column="authority" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryByName" resultMap="AdminMap">
select id,
name,
pwd,
authority
from apsfc.admin
where name = #{name}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="AdminMap">
select id,
name,
pwd,
authority
from apsfc.admin limit #{offset}, #{limit}
</select>
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="AdminMap">
select
id, name, pwd, authority
from apsfc.admin
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="pwd != null and pwd != ''">
and pwd = #{pwd}
</if>
<if test="authority != null and authority != ''">
and authority = #{authority}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into apsfc.admin(name, pwd, authority)
values (#{name}, #{pwd}, #{authority})
</insert>
<!--通过主键修改数据-->
<update id="update">
update apsfc.admin
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="pwd != null and pwd != ''">
pwd = #{pwd},
</if>
<if test="authority != null and authority != ''">
authority = #{authority},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from apsfc.admin
where id = #{id}
</delete>
</mapper>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<title>网上订餐管理员登陆</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #1D3647;
}
-->
</style>
<script language="JavaScript">
function login11() {
if (document.form1.name.value == "") {
alert("请输入用户名!");
document.form1.name.focus();
return false;
}
if (document.form1.pwd.value == "") {
alert("请输入密码!");
document.form1.pwd.focus();
return false;
}
}
</script>
<link href="${pageContext.request.contextPath}/public/admin/css/login.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" height="166" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td height="42" valign="top"><table width="100%" height="42"
border="0" cellpadding="0" cellspacing="0" class="login_top_bg">
<tr>
<td width="100%" height="21"> </td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top"><table width="100%" height="532" border="0"
cellpadding="0" cellspacing="0" class="login_bg">
<tr>
<td width="49%" align="right"><table width="91%" height="532"
border="0" cellpadding="0" cellspacing="0" class="login_bg2">
<tr>
<td height="138" valign="top"><table width="89%"
height="427" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="149"> </td>
</tr>
<tr>
<td height="80" align="right" valign="top"><img
src="${pageContext.request.contextPath}/public/admin/images/logo.png" width="279" height="68"></td>
</tr>
<tr>
<td height="198" align="right" valign="top"><table
width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="35%"> </td>
<td height="25" colspan="2" class="left_txt"
align="center"><p>
<img src="${pageContext.request.contextPath}/public/admin/images/icon-mail2.gif" width="16" height="11">
客户服务邮箱:admin@apsfc.com
</p></td>
</tr>
<tr>
<td> </td>
<td height="25" colspan="2" class="left_txt"
align="center"><p>
<img src="${pageContext.request.contextPath}/public/admin/images/icon-phone.gif" width="17" height="14">
官方网站:http://www.apsfc.com
</p></td>
</tr>
<tr>
<td> </td>
<td height="25" colspan="2" class="left_txt"></td>
</tr>
<tr>
<td> </td>
<td width="30%" height="40"><img
src="${pageContext.request.contextPath}/public/admin//images/icon-demo.gif" width="16" height="16">
使用说明</td>
<td width="35%"><img
src="${pageContext.request.contextPath}/public/admin//images/icon-login-seaver.gif" width="16"
height="16"> 在线客服</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="1%"> </td>
<td width="50%" valign="bottom"><table width="100%"
height="59" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="4%"> </td>
<td width="96%" height="38"><span class="login_txt_bt">登陆网上订餐后台管理</span></td>
</tr>
<tr>
<td> </td>
<td height="21"><table cellSpacing="0" cellPadding="0"
width="100%" border="0" id="table211" height="328">
<tr>
<td height="164" colspan="2" align="middle">
<form name="form1" action="/admin/login"
method="post" onSubmit="return login11()">
<table cellSpacing="0" cellPadding="0" width="100%"
border="0" height="143" id="table212">
<tr>
<td width="13%" height="38" class="top_hui_text"><span
class="login_txt">管理员: </span></td>
<td height="38" colspan="2" class="top_hui_text"><input
name="name" class="name" value="" size="20"></td>
</tr>
<tr>
<td width="13%" height="35" class="top_hui_text"><span
class="login_txt"> 密 码: </span></td>
<td height="35" colspan="2" class="top_hui_text"><input
class="pwd" type="password" size="20" name="pwd">
<img src="${pageContext.request.contextPath}/public/admin//images/luck.gif" width="19" height="18">
</td>
</tr>
<tr>
<td width="13%" height="35"> </td>
<td height="35" colspan="2" class="top_hui_text"><input
class=AutoLogin name=AutoLogin type=checkbox value="Y"
maxLength=4 size=10 id="AutoLogin"> <span
class="login_txt"> 5天内自动登录</span></td>
</tr>
<tr>
<td height="35"> </td>
<td width="20%" height="35"><input name="Submit"
type="submit" class="button" id="Submit" value="登 陆">
</td>
<td width="67%" class="top_hui_text"><input
name="cs" type="button" class="button" id="cs"
value="取 消" onClick="showConfirmMsg1()"></td>
</tr>
</table>
<br>
</form>
</td>
</tr>
<tr>
<td width="433" height="164" align="right" valign="bottom"><img
src="${pageContext.request.contextPath}/public/admin/images/login-wel.gif" width="242" height="138"></td>
<td width="57" align="right" valign="bottom"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="20"><table width="100%" border="0" cellspacing="0"
cellpadding="0" class="login-buttom-bg">
<tr>
<td align="center"><span class="login-buttom-txt">Copyright
© 2015-2020</span></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--开启Spring的注解-->
<context:annotation-config/>
<!--Spring的注解扫描包路径-->
<context:component-scan base-package="com.example"/>
<!--加载数据源连接池-->
<bean name="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/apsfc?serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!--创建SqlSessionFactory对象-->
<bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源连接池-->
<property name="dataSource" ref="druidDataSource"/>
<!--注入Mybatis的主配置文件-->
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
<!--配置DAO的映射文件扫描路径-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!--加载DAO接口扫描-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--将SqlSessionFactory对象进行注入-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!--配置DAO接口的扫描基础路径-->
<property name="basePackage" value="com.example.meal_ordering_system.dao.**"/>
</bean>
<!--加载事务管理器-->
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--加载数据源连接池-->
<property name="dataSource" ref="druidDataSource"/>
</bean>
<!--配置事务增强通知-->
<!--transaction-manager加载指定的事务管理器-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!--事务规则列表-->
<tx:attributes>
<!--propagation定义动作的规则-->
<!--REQUIRED阻断操作-->
<!--NOT_SUPPORTED非阻断操作-->
<!--对新增数据操作的规则定义-->
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<!--对修改数据操作的规则定义-->
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<!--对删除数据操作的规则定义-->
<tx:method name="delete*" propagation="REQUIRED"/>
<!--对查询数据操作的规则定义-->
<tx:method name="get*" propagation="NOT_SUPPORTED"/>
<tx:method name="select*" propagation="NOT_SUPPORTED"/>
<tx:method name="query*" propagation="NOT_SUPPORTED"/>
</tx:attributes>
</tx:advice>
<!--托管通知工具类-->
<bean name="advice" class="com.example.meal_ordering_system.util.AdviceUtil"/>
<!--切面的配置-->
<aop:config>
<!--切面定义在Service层-->
<aop:pointcut id="pointCut" expression="execution(* com.example.meal_ordering_system.service..*(..))"/>
<!--将事务增强通知与切面进行绑定-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/>
<!--切面织入-->
<aop:aspect ref="advice">
<aop:before method="before" pointcut-ref="pointCut"/>
<aop:after method="after" pointcut-ref="pointCut"/>
<aop:around method="around" pointcut-ref="pointCut"/>
<aop:after-throwing method="exception" pointcut-ref="pointCut"/>
</aop:aspect>
</aop:config>
</beans>