SSM项目 蟹堡王餐厅管理系统(二)项目配置和数据库设计

一、项目结构预览

(一)后端结构

在这里插入图片描述

(二)前端页面

在这里插入图片描述
(1)css

body
{
    margin:0;
    padding: 0;
    font-family: sans-serif;

    background-size: cover;
}
.box
{
    position: absolute;
    top:50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width:400px;
    padding: 40px;
    background: rgba(0,0,0,.8);
    box-sizing : border-box;
    box-shadow: 0 15px 25px rgba(0,0,0,.5);
    border-radius: 10px;
    text-align: center;
    margin: auto;
}
.box h2
{
    margin:0 0 30px;
    padding: 0;
    color: #fff;
    text-align: center;
}
.box .inputBox
{
    position: relative;
}
.box .inputBox input
{
    width:100%;
    padding: 10px 0;
    font-size: 16px;
    color: #fff;
    letter-spacing: 1px;
    margin-bottom: 30px;
    border: none;
    border-bottom: 1px solid #fff;
    outline: none;
    background: transparent;
}
.box .inputBox label
{
    position: absolute;
    top:0;
    left: 0;
    padding: 10px 0;
    letter-spacing: 1px;
    font-size: 16px;
    color: #fff;
    pointer-events: none;
    transition: .5s;
}
.box .inputBox input:focus ~ label,
.box .inputBox input:valid ~ label
{
    top:-18px;
    left:0;
    color:#03a9f4;
    font-size: 12px;
}
.box input[type="submit"]
{
    background: transparent;

    border: none;
    outline:none;
    color: #fff;
    background: #03a9f4;
    padding: 10px 20px;
    cursor:pointer;
    border-radius: 5px;
}
.box Button
{
    background: transparent;

    border: none;
    outline:none;
    color: #fff;
    background: #03a9f4;
    padding: 10px 20px;
    cursor:pointer;
    border-radius: 5px;
}

.box .inputBox img
{
    width:100%;
    padding: 10px 0;
    font-size: 16px;
    color: #fff;
    letter-spacing: 1px;
    margin-bottom: 30px;
    border: none;
    outline: none;
    background: transparent;
}

(2)images:项目所用到图片。
(3)js:jQuery。
(4)layui:请从layui官网自行下载。

(三)配置文件

在这里插入图片描述

二、项目配置

(一)db.properties

配置数据库信息,包括数据库驱动,数据库连接,用户名和密码。

jdbc.driverClass=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/kkdb?useSSL=TRUE&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
jdbc.username=root
jdbc.password=123456

(1)jdbc.driverClass为数据库驱动名,我是Mysql8.0版本所以需要加上cj。
(2)jdbc.url为数据库连接,kkdb为数据库名,Mysql8.0版本需要在连接中加上时区。
(3)jdbc.username为连接数据库的用户名。
(4)jdbc.password为连接数据库的密码。

(二)mybatis-config.xml

配置mybatis,由于使用spring,大部分配置都在spring的配置文件中实现,我这里仅实现分页插件PageHelper的声明,也可以保留mybatis的其他配置,方便测试使用。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--核心配置文件-->
<configuration>

    <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>


</configuration>

(三)spring-config.xml

<?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:component-scan base-package="com.RH.controller"/>
    <context:component-scan base-package="com.RH.service"/>
    <context:component-scan base-package="com.RH.db.dao"/>
    <context:component-scan base-package="com.RH.utils"/>

    <!-- 读取db.propertise文件内容  -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- spring管理数据源dataSource对象,数据库连接池	 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <!--
			数据库连接池相关配置
 			项目只要启动,就向数据库连接池中注入initialSize=10个链接,这些连接都是待机状态,使用时不用创建对象而是直接从连接池中取出,使用结束后也不需要关闭连接,而是重新回归池中
		-->
        <property name="initialSize" value="10"/>
        <property name="minIdle" value="10"/>
        <property name="maxActive" value="50"/>
        <property name="maxWait" value="60000"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="minEvictableIdleTimeMillis" value="300000"/>
    </bean>

    <!-- 让spring管理mybatis核心对象sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 给sqlSessionFactory对象注入数据源dataSource属性值 -->
        <property name="dataSource" ref="dataSource"></property>
        <!-- 给sqlSessionFactory对象注入给实体类起别名typeAliasesPackage属性值 -->
        <property name="typeAliasesPackage" value="com.RH.db.pojo"></property>
        <!-- 给sqlSessionFactory对象注入注册mapper.xml映射文件mapperLocations属性值 -->
        <property name="mapperLocations" value="classpath:com/RH/db/mapping/*.xml"></property>
        <!-- 给sqlSessionFactory对象注入mybatis.xml核心配置文件configLocation属性值 -->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
    </bean>

    <!-- spring管理事务	 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 只要方法名带有delete、save、update、insert,那么这些方法就开启了事务 -->
            <tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/>
            <!-- 只要方法名带有load、find、search、select、get,那么这些方法就不会开启事务 -->
            <tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="search*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!--
        因为dao层下所有的文件都是接口,接口的方法没有方法体,所以当数据请求结束后,dao接口方法无法提交或回滚事务
        需要让service层的方法调用dao接口的方法,然后对事务进行提交或回滚

        所以,利用面向切面编程将所有事务的管理,配置到service包下的所有类的所有方法中,只要方法名带有delete、save、update、insert,就会对事务自行处理
     -->
    <aop:config>
        <aop:pointcut id="serviceMethods" expression="execution(* com.RH.service.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
    </aop:config>

    <!-- 只有配置了以下内容后,才可以在Dao层接口上使用@Repository注解 -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.RH.db.dao"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>


</beans>

(四)springMvc.xml

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--扫描控制器,哪个类头上有@Controller,那么这个类就可以接收请求 -->
    <context:component-scan base-package="com.RH.controller"/>
    <!-- 注册注解:@ResponseBody @RequestMapping @Controller -->
    <mvc:annotation-driven/>
    <!-- 过滤静态资源请求,例如:页面引入了 js/jquery.js,那么利用这个配置,就不会把页面引入的文件当作请求了 -->
    <mvc:default-servlet-handler/>

    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/"></property>
        <!-- 后缀 -->
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!--
		如果项目中拥有jackson.jar,那么springMvc会借助@ResponseBody将返回结果自动转换为json,如果项目没有jackson.jar
		如果项目用的fastjson.jar,那么需要特殊配置以下
		利用jastjson.jar,将@ResponseBody返回结果自动转换为json
	-->
    <mvc:annotation-driven>
        <!-- 安装FastJson,转换器 -->
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <!-- 声明转换类型:json -->
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- 上传/下载解析器 id必须是:“multipartResolver”-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 最大可上传的文件大小  单位:byte  超出后会抛出MaxUploadSizeExceededException异常,可以异常解析器捕获 -->
        <property name="maxUploadSize" value="104857600"></property>
    </bean>
</beans>

(五)web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>System</display-name>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>

  <!-- 用来监听Context容器的加载 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 启动项目向ApplicationContext中配置spring.xml文件 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-config.xml</param-value>
  </context-param>

  <!-- 关与springMvc的配置 -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <!-- 前端控制器:总调度,负责拿到所有的请求 -->
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <!-- springMvc.xml文件的路径   classpath:路径就代表项目中的resources文件夹-->
      <param-value>classpath:springMvc.xml</param-value><!-- 利用映射器 派发所有请求、适配器  处理所有参数-->
    </init-param>
    <!-- 项目启动后,优先加载级别,数字越小,那么级别越高 -->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 用来生成验证码 -->
  <servlet>
    <servlet-name>cap</servlet-name>
    <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
    <init-param>
      <param-name>kaptcha.border</param-name>
      <param-value>no</param-value>
    </init-param>
    <init-param>
      <param-name>kaptcha.textproducer.char.length</param-name>
      <param-value>4</param-value>
    </init-param>
    <init-param>
      <param-name>kaptcha.textproducer.char.string</param-name>
      <param-value>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</param-value>
    </init-param>
    <init-param>
      <param-name>kaptcha.background.clear.to</param-name>
      <param-value>211,229,237</param-value>
    </init-param>
    <init-param>
      <!-- 向session中存入验证码:session.setAttribute("captcha","生成的四位随机数") -->
      <param-name>kaptcha.session.key</param-name>
      <param-value>captcha</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>cap</servlet-name>
    <!-- 接收到img的src发送的请求 -->
    <url-pattern>/captcha</url-pattern>
  </servlet-mapping>


  <!-- 编码格式过滤器,所有请求都会经过这个过滤器 -->
  <filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- 它是一个在web应用关闭的时候,清除JavaBeans Introspector的监听器.在web.xml中注册这个listener.可以保证在web 应用关闭的时候释放与掉这个web 应用相关的class loader 和由它管理的类  -->
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
</web-app>

三、数据库设计

(一)数据库结构预览

在这里插入图片描述

(二)数据库设计

本项目共有八张表,分别为user表(用户表)、、authority表(权限分类表)、user_authority表(用户权限关联表)、food表(菜品表)、type表(菜品种类表)、food_type表(菜品种类关联表)、order表(订单表)、order_detils表(订单详情表)。

(1)user表(用户表):主键为自增的uid,该表属性包括userName(用户名)、userPsd(用户密码)、sex(性别)、headImg(用户头像名称)、imgPath(图片存储路径)。

CREATE TABLE `user` (
  `uid` int NOT NULL AUTO_INCREMENT,
  `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `userPsd` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `sex` varchar(24) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `headImg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `imgPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(2)authority表(权限分类表):主键为自增的aid,属性为authorityType(用户权限),权限分为三种,012,分别对应老板、员工、注册用户,每个新注册用户的默认权限都是2也就是注册用户。

CREATE TABLE `authority` (
  `aid` int NOT NULL AUTO_INCREMENT,
  `authorityType` int DEFAULT NULL,
  PRIMARY KEY (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(3)user_authority表(用户权限关联表):主键为uaid,属性为uid(用户表主键)、aid(权限表主键),两表通过uid和aid进行关联。

CREATE TABLE `user_authority` (
  `uaid` int NOT NULL AUTO_INCREMENT,
  `uid` int DEFAULT NULL,
  `aid` int DEFAULT NULL,
  PRIMARY KEY (`uaid`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(4)food表(菜品表):主键为自增的fid,属性包括foodName(菜品名称)、foodDescription(菜品描述)、foodPrice(菜品价格)、foodImg(图片名称)、foodImgPath(图片存储路径)

CREATE TABLE `food` (
  `fid` int NOT NULL AUTO_INCREMENT,
  `foodName` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `foodDescription` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `foodPrice` double(6,2) DEFAULT NULL,
  `foodImg` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  `foodImgPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`fid`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(5)type表(菜品种类表):主键为自增的tid,属性为foodType(菜品种类),定义为三种,汉堡、饮料和小食。

CREATE TABLE `type` (
  `tid` int NOT NULL AUTO_INCREMENT,
  `foodType` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`tid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(6)food_type表(菜品种类关联表):主键为自增的ftid,属性为fid(菜品表主键)、tid(种类表主键),两表通过fid和tid进行关联。

CREATE TABLE `food_type` (
  `ftid` int NOT NULL AUTO_INCREMENT,
  `fid` int DEFAULT NULL,
  `tid` int DEFAULT NULL,
  PRIMARY KEY (`ftid`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(7)order表(订单表):主键为自增的oid,属性包括uid(用户表主键)、userName(下单人用户名)、totalMoney(该订单总价)。

CREATE TABLE `order` (
  `oid` int NOT NULL AUTO_INCREMENT,
  `uid` int DEFAULT NULL,
  `userName` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `totalMoney` double(6,2) DEFAULT NULL,
  PRIMARY KEY (`oid`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

(8)order_detils表(订单详情表):主键为自增的odid,属性为oid(order表主键)、fid(菜品表主键)、foodName(菜品名称)、foodPrice(菜品价格)、orderNum(订购数量)。

CREATE TABLE `order_detils` (
  `odid` int NOT NULL AUTO_INCREMENT,
  `oid` int DEFAULT NULL,
  `fid` int DEFAULT NULL,
  `foodName` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `foodPrice` double(6,2) DEFAULT NULL,
  `orderNum` int DEFAULT NULL,
  PRIMARY KEY (`odid`)
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值