1.项目概述

1.1.项目演示

  1. 运行 “饿了么项目” ,演示应用程序效果,演示 “点餐业务线” 整体流程。
  2. 本项目参照 “饿了么官网网页版”制作,演示饿了么官网效果。饿了么网页版:http://h5.ele.me/
  3. 本项目专注于完成点餐业务线功能, ”饿了么官网“中的其它功能暂不涉及 。

    1.2.项目目标

  4. 本项目为课程级贯穿项目中的第三个项目(JDBC项目、前端项目、javaWeb项目)的服务器端升级版。
    数据库结构与前端Vue没有任何变化,而服务器端由Servlet升级为SpringBoot。

  5. 本项目完成后,学员将能够使用VUE+SpringBoot+AJAX技术开发前后端分离的Web应用程序。

    1.3.数据库设计

    1.3.1.DB一览表

    | No | 表名称 | 中文名 | 说明 | | :—- | :—- | :—- | :—- | | 1 | business | 商家表 | 存储所有商家信息 | | 2 | food | 食品表 | 存储每个商家所拥有的所有食品信息 | | 3 | cart | 购物车表 | 存储每个用户的购物车中的食品信息 | | 4 | deliveryaddress | 送货地址表 | 存储每个用户的所有送货地址信息 | | 5 | orders | 订单表 | 存储每个用户的所有订单信息 | | 6 | orderdetailet | 订单明细表 | 存储每个订单中所订购的所有食品信息 | | 7 | user | 用户表 | 存储所有用户信息 |

1.3.2.表结构

约束类型标识: PK:primary key 主键 FK:foreign key 外键 NN:not null 非空 UQ:unique 唯一索引 AI:auto increment 自增长列

1.3.2.1.business(商家表)

No 字段名 数据类型 size 默认値 约束 说明
1 businessId int PK、AI、NN 商家编号
2 businessName varchar 40 NN 商家名称
3 businessAddress varchar 50 商家地址
4 businessExplain varchar 40 商家介绍
5 businessImg mediumtext NN 商家图片
6 orderTypeId int NN 点餐分类: 1:美食、2:早餐、3:跑腿代购、4:汉堡披萨、5:甜品饮品、6:速食简餐、7:地方小吃、8:米粉面馆、9:包子粥铺、10:炸鸡炸串
7 starPrice decimal (5,2) 0.00 起送费
8 deliveryPrice decimal (5,2) 0.00 配送费
9 remarks varchar 40 备注

1.3.2.2.food(食品表)

No 字段名 数据类型 size 默认値 约束 说明
1 foodId int PK、AI、NN 食品编号
2 foodName varchar 30 NN 食品名称
3 foodExplain varchar 30 NN 食品介绍
4 foodImg mediumtext NN 食品图片
5 foodPrice decimal (5,2) NN 食品价格
6 businessId int FK、NN 所属商家编号
7 remarks varchar 40 备注

1.3.2.3.cart(购物车表)

No 字段名 数据类型 size 默认値 约束 说明
1 cartId int PK、AI、NN 无意义编号
2 foodId int FK、NN 食品编号
3 businessId int FK、NN 所属商家编号
4 userId varchar 20 FK、NN 所属用户编号
5 quantity int NN 同一类型食品的购买数量

1.3.2.4.deliveryaddress(送货地址表)

No 字段名 数据类型 size 默认値 约束 说明
1 daId int PK、AI、NN 送货地址编号
2 contactName varchar 20 NN 联系人姓名
3 contactSex int NN 联系人性别
4 contactTel varchar 20 NN 联系人电话
5 address varchar 100 NN 送货地址
6 userId varchar 20 FK、NN 所属用户编号

1.3.2.5.orders(订单表)

No 字段名 数据类型 size 默认値 约束 说明
1 orderId int PK、AI、NN 订单编号
2 userId varchar 20 FK、NN 所属用户编号
3 businessId int FK、NN 所属商家编号
4 orderDate varchar 20 NN 订购日期
5 orderTotal decimal (7,2) 0.00 NN 订单总价
6 daId int FK、NN 所属送货地址编号
7 orderState int 0 NN 订单状态(0:未支付; 1:已支付)

1.3.2.6.orderdetailet(订单明细表)

No 字段名 数据类型 size 默认値 约束 说明
1 odId int PK、AI、NN 订单明细编号
2 orderId int FK、NN 所属订单编号
3 foodId int FK、NN 所属食品编号
4 quantity int NN 数量

1.3.2.7.user(用户表)

No 字段名 数据类型 size 默认値 约束 说明
1 userId varchar 20 PK、NN 用户编号
2 password varchar 20 NN 密码
3 userName varchar 20 NN 用户名称
4 userSex int 1 NN 用户性别(1:男; 0:女)
5 userImg mediumtext 用户头像
6 delTag int 1 NN 删除标记(1:正常; 0:删除)

1.4.业务流程

Java框架阶段项目--饿了么课件 - 图1

2.服务器端项目搭建

2.1.开发环境检查

  1. 开发工具:SpringToolSuite(STS)
  2. 检查开发工具的jdk配置:jdk8
  3. 检查maven构建工具的配置:maven3
  4. 检查开发工具的文件编码配置:utf-8

    2.2.搭建springboot工程总体架构

    2.2.1.工程类型

    创建工程类型:Spring Starter project
    Java框架阶段项目--饿了么课件 - 图2

    2.2.2.pom.xml文件

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    4. <modelVersion>4.0.0</modelVersion>
    5. <parent>
    6. <groupId>org.springframework.boot</groupId>
    7. <artifactId>spring-boot-starter-parent</artifactId>
    8. <version>2.3.0.RELEASE</version>
    9. <relativePath/> <!-- lookup parent from repository -->
    10. </parent>
    11. <groupId>com.neusoft</groupId>
    12. <artifactId>elmboot</artifactId>
    13. <version>0.0.1-SNAPSHOT</version>
    14. <name>elmboot</name>
    15. <description>Demo project for Spring Boot</description>
    16. <properties>
    17. <java.version>1.8</java.version>
    18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    19. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    20. </properties>
    21. <dependencies>
    22. <dependency>
    23. <groupId>org.springframework.boot</groupId>
    24. <artifactId>spring-boot-starter</artifactId>
    25. </dependency>
    26. <dependency>
    27. <groupId>org.springframework.boot</groupId>
    28. <artifactId>spring-boot-starter-web</artifactId>
    29. </dependency>
    30. <dependency>
    31. <groupId>org.mybatis.spring.boot</groupId>
    32. <artifactId>mybatis-spring-boot-starter</artifactId>
    33. <version>2.0.1</version>
    34. </dependency>
    35. <dependency>
    36. <groupId>mysql</groupId>
    37. <artifactId>mysql-connector-java</artifactId>
    38. <version>5.1.6</version>
    39. <scope>runtime</scope>
    40. </dependency>
    41. <dependency>
    42. <groupId>org.springframework.boot</groupId>
    43. <artifactId>spring-boot-starter-test</artifactId>
    44. <scope>test</scope>
    45. <exclusions>
    46. <exclusion>
    47. <groupId>org.junit.vintage</groupId>
    48. <artifactId>junit-vintage-engine</artifactId>
    49. </exclusion>
    50. </exclusions>
    51. </dependency>
    52. </dependencies>
    53. <build>
    54. <plugins>
    55. <plugin>
    56. <groupId>org.springframework.boot</groupId>
    57. <artifactId>spring-boot-maven-plugin</artifactId>
    58. </plugin>
    59. </plugins>
    60. </build>
    61. </project>

    2.2.3.工程目录结构

    Java框架阶段项目--饿了么课件 - 图3

    2.2.4.SpringBoot入口文件

    1. package com.neusoft.elmboot;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. @SpringBootApplication
    5. public class ElmbootApplication {
    6. public static void main(String[] args) {
    7. SpringApplication.run(ElmbootApplication.class, args);
    8. }
    9. }

    2.2.5.处理跨域的Cors配置文件

    1. package com.neusoft.elmboot;
    2. import org.springframework.context.annotation.Bean;
    3. import org.springframework.context.annotation.Configuration;
    4. import org.springframework.web.servlet.config.annotation.CorsRegistry;
    5. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    6. @Configuration
    7. public class WebMvcConfig {
    8. @Bean
    9. public WebMvcConfigurer corsConfigurer() {
    10. return new WebMvcConfigurer() {
    11. @Override
    12. public void addCorsMappings(CorsRegistry registry) {
    13. registry.addMapping("/**")
    14. .allowedOrigins("http://localhost:8081")
    15. .allowCredentials(true)
    16. .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
    17. .allowedHeaders("*")
    18. .maxAge(36000);
    19. }
    20. };
    21. }
    22. }

    2.2.6.application.properties配置文件

    1. server.port=8080
    2. server.servlet.context-path=/elm
    3. logging.level.org.springframework=debug
    4. logging.level.com.neusoft.elmboot.mapper=debug
    5. spring.datasource.username=root
    6. spring.datasource.password=123
    7. spring.datasource.url=jdbc:mysql://localhost:3306/elm?characterEncoding=utf-8
    8. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    9. mybatis.mapper-locations=classpath:mapper/*.xml
    10. mybatis.type-aliases-package=com.neusoft.elmboot.po

    2.3.服务器接口API

    2.3.1.business

  5. BusinessController/listBusinessByOrderTypeId 参数:orderTypeId 返回值:business数组 功能:根据点餐分类编号查询所属商家信息

  6. BusinessController/getBusinessById 参数:businessId 返回值:business对象 功能:根据商家编号查询商家信息

    2.3.2.food

  7. FoodController/listFoodByBusinessId 参数:businessId 返回值:food数组 功能:根据商家编号查询所属食品信息

    2.3.3.cart

  8. CartController/listCart 参数:userId、businessId(可选) 返回值:cart数组(多对一:所属商家信息、所属食品信息) 功能:根据用户编号查询此用户所有购物车信息 根据用户编号和商家编号,查询此用户购物车中某个商家的所有购物车信息

  9. CartController/saveCart 参数:userId、businessId、foodId 返回值:int(影响的行数) 功能:向购物车表中添加一条记录
  10. CartController/updateCart 参数:userId、businessId、foodId、quantity 返回值:int(影响的行数) 功能:根据用户编号、商家编号、食品编号更新数量
  11. CartController/removeCart 参数:userId、businessId、foodId(可选) 返回值:int(影响的行数) 功能:根据用户编号、商家编号、食品编号删除购物车表中的一条食品记录 根据用户编号、商家编号删除购物车表中的多条条记录

    2.3.4.deliveryAddress

  12. DeliveryAddressController/listDeliveryAddressByUserId 参数:userId 返回值:deliveryAddress数组 功能:根据用户编号查询所属送货地址

  13. DeliveryAddressController/getDeliveryAddressById 参数:daId 返回值:deliveryAddress对象 功能:根据送货地址编号查询送货地址
  14. DeliveryAddressController/saveDeliveryAddress 参数:contactName、contactSex、contactTel、address、userId 返回值:int(影响的行数) 功能:向送货地址表中添加一条记录
  15. DeliveryAddressController/updateDeliveryAddress 参数:daId、contactName、contactSex、contactTel、address、userId 返回值:int(影响的行数) 功能:根据送货地址编号更新送货地址信息
  16. DeliveryAddressController/removeDeliveryAddress 参数:daId 返回值:int(影响的行数) 功能:根据送货地址编号删除一条记录

    2.3.5.orders

  17. OrdersController/createOrders 参数:userId、businessId、daId、orderTotal 返回值:int(订单编号) 功能:根据用户编号、商家编号、订单总金额、送货地址编号向订单表中添加一条记录, 并获取自动生成的订单编号, 然后根据用户编号、商家编号从购物车表中查询所有数据,批量添加到订单明细表中, 然后根据用户编号、商家编号删除购物车表中的数据。

  18. OrdersController/getOrdersById 参数:orderId 返回值:orders对象(包括多对一:商家信息; 一对多:订单明细信息) 功能:根据订单编号查询订单信息,包括所属商家信息,和此订单的所有订单明细信息
  19. OrdersController/listOrdersByUserId 参数:userId 返回值:orders数组(包括多对一:商家信息; 一对多:订单明细信息) 功能:根据用户编号查询此用户的所有订单信息

    2.3.6.user

  20. UserController/getUserByIdByPass 参数:userId、password 返回值:user对象 功能:根据用户编号与密码查询用户信息

  21. UserController/getUserById 参数:userId 返回值:int(返回行数) 功能:根据用户编号查询用户表返回的行数
  22. UserController/saveUser 参数:userId、password、userName、userSex 返回值:int(影响的行数) 功能:向用户表中添加一条记录

    3.前端项目搭建

    3.1.开发环境检查

  23. 检查cnpm安装环境: 命令行下输入:cnpm -v

  24. 检查VueCli安装环境:命令行下输入:vue -V (注意:本工程使用VueCli4.0.0以上版本)

    附录:

    1. 安装npm:直接安装node.js (输入 “npm -v” 测试是否安装成功; 输入 node –v 查看node版本)
    2. 安装cnpm:npm install -g cnpm —registry=https://registry.npm.taobao.org
    3. 全局安装vuecli:cnpm install -g @vue/cli (或:npm install -g @vue/cli@4.x.x)
    4. 查看当前安装的vue-cli版本:vue —version 或 vue –V
    5. 卸载旧版本的vue-cli:cnpm uninstall vue-cli -g
    6. 查看远程仓库中的版本号:cnpm view @vue/cli versions —json

3.2.搭建VueCli工程总体架构

3.2.1.搭建VueCli模板工程

  1. 命令行下进入工作空间目录中,输入: vue create elmclient (工程名必须小写)
  2. 选择预设模板:这里选择“Manually select features”(手动选择特征)
  3. 模块选取:Babel、Router
  4. 选择是否使用history 形式的路由:选择:Y
  5. 将依赖文件放在package.json中:选择:“in package.json”
  6. 是否将当前选择保存以备下次使用:选择:N
  7. 进入创建好的工程目录:cd elmclient
  8. 启动工程:npm run serve
  9. 在浏览器中测试:http://localhost:8080

    3.2.2.添加其它依赖及配置文件

  10. 添加font-awesome与axios依赖: cnpm install font-awesome —save cnpm install axios —save cnpm install qs —save

  11. 添加图片到src的assets中。
  12. 在src目录下添加common.js文件

    1. //获取当前时间(XXXX-XX-XX)
    2. export function getCurDate() {
    3. var now = new Date();
    4. var year = now.getFullYear();
    5. var month = now.getMonth() + 1;
    6. var day = now.getDate();
    7. month = month < 10 ? "0" + month : month;
    8. day = day < 10 ? "0" + day : day;
    9. return year + "-" + month + "-" + day;
    10. }
    11. //向sessionStorage中存储一个JSON对象
    12. export function setSessionStorage(keyStr, value) {
    13. sessionStorage.setItem(keyStr, JSON.stringify(value));
    14. }
    15. //从sessionStorage中获取一个JSON对象(取不到时返回null)
    16. export function getSessionStorage(keyStr) {
    17. var str = sessionStorage.getItem(keyStr);
    18. if (str == '' || str == null || str == 'null' || str == undefined) {
    19. return null;
    20. } else {
    21. return JSON.parse(str);
    22. }
    23. }
    24. //从sessionStorage中移除一个JSON对象
    25. export function removeSessionStorage(keyStr) {
    26. sessionStorage.removeItem(keyStr);
    27. }
    28. //向localStorage中存储一个JSON对象
    29. export function setLocalStorage(keyStr, value) {
    30. localStorage.setItem(keyStr, JSON.stringify(value));
    31. }
    32. //从localStorage中获取一个JSON对象(取不到时返回null)
    33. export function getLocalStorage(keyStr) {
    34. var str = localStorage.getItem(keyStr);
    35. if (str == '' || str == null || str == 'null' || str == undefined) {
    36. return null;
    37. } else {
    38. return JSON.parse(str);
    39. }
    40. }
    41. //从localStorage中移除一个JSON对象
    42. export function removeLocalStorage(keyStr) {
    43. localStorage.removeItem(keyStr);
    44. }
  13. 在工程根目录下添加vue.config.js文件

    1. module.exports = {
    2. devServer: {
    3. port: 8081
    4. }
    5. }

    3.2.3.main.js文件

    1. import Vue from 'vue'
    2. import App from './App.vue'
    3. import router from './router'
    4. import 'font-awesome/css/font-awesome.min.css'
    5. import axios from 'axios'
    6. import qs from 'qs'
    7. import {
    8. getCurDate,
    9. setSessionStorage,
    10. getSessionStorage,
    11. removeSessionStorage,
    12. setLocalStorage,
    13. getLocalStorage,
    14. removeLocalStorage
    15. } from './common.js'
    16. Vue.config.productionTip = false
    17. //设置axios的基础url部分
    18. axios.defaults.baseURL = 'http://localhost:8080/elm/';
    19. //将axios挂载到vue实例上,使用时就可以 this.$axios 这样使用了
    20. Vue.prototype.$axios = axios;
    21. Vue.prototype.$qs = qs;
    22. Vue.prototype.$getCurDate = getCurDate;
    23. Vue.prototype.$setSessionStorage = setSessionStorage;
    24. Vue.prototype.$getSessionStorage = getSessionStorage;
    25. Vue.prototype.$removeSessionStorage = removeSessionStorage;
    26. Vue.prototype.$setLocalStorage = setLocalStorage;
    27. Vue.prototype.$getLocalStorage = getLocalStorage;
    28. Vue.prototype.$removeLocalStorage = removeLocalStorage;
    29. router.beforeEach(function(to,from,next){
    30. let user = sessionStorage.getItem('user');
    31. //除了登录、注册、首页、商家列表、商家信息之外,都需要判断是否登录
    32. if(!(to.path=='/'||to.path=='/index'||to.path=='/businessList'||to.path=='/businessInfo'||to.path=='/login'||to.path=='/register')){
    33. if(user==null){
    34. router.push('/login');
    35. location.reload();
    36. }
    37. }
    38. next();
    39. });
    40. new Vue({
    41. router,
    42. render: h => h(App)
    43. }).$mount('#app')

    3.2.4.App.vue文件

    注意:在App.vue文件中,#app的高度也要设置为100%。

    1. <template>
    2. <div id="app">
    3. <router-view />
    4. </div>
    5. </template>
    6. <!-- 这里是共通样式,适用于所有组件,所以不要加scoped -->
    7. <style>
    8. html,body,div,span,h1,h2,h3,h4,h5,h6,ul,ol,li,p {
    9. margin: 0;
    10. padding: 0;
    11. }
    12. html,body,#app {
    13. width: 100%;
    14. height: 100%;
    15. font-family: "微软雅黑";
    16. }
    17. ul,ol {
    18. list-style: none;
    19. }
    20. a {
    21. text-decoration: none;
    22. }
    23. </style>

    3.2.5.路由index.js文件

    1. import Vue from 'vue'
    2. import VueRouter from 'vue-router'
    3. import Index from '../views/Index.vue'
    4. import BusinessList from '../views/BusinessList.vue'
    5. import BusinessInfo from '../views/BusinessInfo.vue'
    6. import Login from '../views/Login.vue'
    7. import Orders from '../views/Orders.vue'
    8. import UserAddress from '../views/UserAddress.vue'
    9. import Payment from '../views/Payment.vue'
    10. import OrderList from '../views/OrderList.vue'
    11. import AddUserAddress from '../views/AddUserAddress.vue'
    12. import EditUserAddress from '../views/EditUserAddress.vue'
    13. import Register from '../views/Register.vue'
    14. Vue.use(VueRouter)
    15. const routes = [{
    16. path: '/',
    17. name: 'Home',
    18. component: Index
    19. }, {
    20. path: '/index',
    21. name: 'Index',
    22. component: Index
    23. }, {
    24. path: '/businessList',
    25. name: 'BusinessList',
    26. component: BusinessList
    27. }, {
    28. path: '/businessInfo',
    29. name: 'BusinessInfo',
    30. component: BusinessInfo
    31. }, {
    32. path: '/login',
    33. name: 'Login',
    34. component: Login
    35. }, {
    36. path: '/orders',
    37. name: 'Orders',
    38. component: Orders
    39. }, {
    40. path: '/userAddress',
    41. name: 'UserAddress',
    42. component: UserAddress
    43. }, {
    44. path: '/payment',
    45. name: 'Payment',
    46. component: Payment
    47. }, {
    48. path: '/orderList',
    49. name: 'OrderList',
    50. component: OrderList
    51. }, {
    52. path: '/addUserAddress',
    53. name: 'AddUserAddress',
    54. component: AddUserAddress
    55. }, {
    56. path: '/editUserAddress',
    57. name: 'EditUserAddress',
    58. component: EditUserAddress
    59. }, {
    60. path: '/register',
    61. name: 'Register',
    62. component: Register
    63. }
    64. ]
    65. //解决重复路由报异常问题
    66. const originalPush = VueRouter.prototype.push;
    67. VueRouter.prototype.push = function push(location) {
    68. return originalPush.call(this, location).catch(err => err)
    69. }
    70. const router = new VueRouter({
    71. mode: 'history',
    72. base: process.env.BASE_URL,
    73. routes
    74. })
    75. export default router

    4.项目代码

    4.1.领域模型(PO)

    4.1.1.Business

    1. package com.neusoft.elm.po;
    2. public class Business {
    3. private Integer businessId;
    4. private String businessName;
    5. private String businessAddress;
    6. private String businessExplain;
    7. private String businessImg;
    8. private Integer orderTypeId;
    9. private double starPrice; //起送费
    10. private double deliveryPrice; //配送费
    11. private String remarks;
    12. //get、set ... ...
    13. }

    4.1.2.Cart

    1. public class Cart {
    2. private Integer cartId;
    3. private Integer foodId;
    4. private Integer businessId;
    5. private String userId;
    6. private Integer quantity;
    7. //多对一:所属食品
    8. private Food food;
    9. //多对一:所属商家
    10. private Business business;
    11. //get、set ... ...
    12. }

    4.1.3.DeliveryAddress

    1. public class DeliveryAddress {
    2. private Integer daId;
    3. private String contactName;
    4. private Integer contactSex;
    5. private String contactTel;
    6. private String address;
    7. private String userId;
    8. //get、set ... ...
    9. }

    4.1.4.Food

    1. public class Food {
    2. private Integer foodId;
    3. private String foodName;
    4. private String foodExplain;
    5. private String foodImg;
    6. private Double foodPrice;
    7. private Integer businessId;
    8. private String remarks;
    9. //get、set ... ...
    10. }

    4.1.5.OrderDetailet

    1. private Integer odId;
    2. private Integer odId;
    3. private Integer orderId;
    4. private Integer foodId;
    5. private Integer quantity;
    6. //多对一:所属食品
    7. private Food food;
    8. //get、set ... ...
    9. }

    4.1.6.Orders

    1. public class Orders {
    2. private Integer orderId;
    3. private String userId;
    4. private Integer businessId;
    5. private String orderDate;
    6. private Double orderTotal;
    7. private Integer daId; //送货地址编号
    8. private Integer orderState; //订单状态(0:未支付; 1:已支付)
    9. //多对一:所属商家
    10. private Business business;
    11. //一对多:订单明细
    12. private List<OrderDetailet> list;
    13. //get、set ... ...
    14. }

    4.1.7.User

    1. public class User {
    2. private String userId;
    3. private String password;
    4. private String userName;
    5. private Integer userSex;
    6. private String userImg;
    7. private Integer delTag;
    8. //get、set ... ...
    9. }

    4.2.服务器端代码

    4.2.1.Mapper层代码

    4.2.1.1.Business

    1. package com.neusoft.elmboot.mapper;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import org.apache.ibatis.annotations.Select;
    5. import com.neusoft.elmboot.po.Business;
    6. @Mapper
    7. public interface BusinessMapper {
    8. @Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
    9. public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);
    10. @Select("select * from business where businessId=#{businessId}")
    11. public Business getBusinessById(Integer businessId);
    12. }

    4.2.1.2.Cart

    1. package com.neusoft.elmboot.mapper;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Insert;
    4. import org.apache.ibatis.annotations.Mapper;
    5. import org.apache.ibatis.annotations.Update;
    6. import com.neusoft.elmboot.po.Cart;
    7. @Mapper
    8. public interface CartMapper {
    9. public List<Cart> listCart(Cart cart);
    10. @Insert("insert into cart values(null,#{foodId},#{businessId},#{userId},1)")
    11. public int saveCart(Cart cart);
    12. @Update("update cart set quantity=#{quantity} where foodId=#{foodId} and businessId=#{businessId} and userId=#{userId}")
    13. public int updateCart(Cart cart);
    14. public int removeCart(Cart cart);
    15. }
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    4. <mapper namespace="com.neusoft.elmboot.mapper.CartMapper">
    5. <resultMap type="Cart" id="cartResultMap">
    6. <id column="cartId" property="cartId"/>
    7. <result column="foodId" property="foodId"/>
    8. <result column="businessId" property="businessId"/>
    9. <result column="userId" property="userId"/>
    10. <result column="quantity" property="quantity"/>
    11. <association property="food" javaType="Food"
    12. select="com.neusoft.elmboot.mapper.FoodMapper.getFoodById" column="foodId"/>
    13. <association property="business" javaType="Business"
    14. select="com.neusoft.elmboot.mapper.BusinessMapper.getBusinessById" column="businessId"/>
    15. </resultMap>
    16. <select id="listCart" parameterType="Cart" resultMap="cartResultMap">
    17. select * from cart
    18. <where>
    19. userId=#{userId}
    20. <if test="businessId!=null and businessId!=''">
    21. and businessId=#{businessId}
    22. </if>
    23. </where>
    24. order by cartId
    25. </select>
    26. <delete id="removeCart" parameterType="Cart">
    27. delete from cart
    28. <where>
    29. userId=#{userId} and businessId=#{businessId}
    30. <if test="foodId!=null and foodId!=''">
    31. and foodId=#{foodId}
    32. </if>
    33. </where>
    34. </delete>
    35. </mapper>

    4.2.1.3.DeliveryAddress

    1. package com.neusoft.elmboot.mapper;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Delete;
    4. import org.apache.ibatis.annotations.Insert;
    5. import org.apache.ibatis.annotations.Mapper;
    6. import org.apache.ibatis.annotations.Select;
    7. import org.apache.ibatis.annotations.Update;
    8. import com.neusoft.elmboot.po.DeliveryAddress;
    9. @Mapper
    10. public interface DeliveryAddressMapper {
    11. @Select("select * from deliveryAddress where userId=#{userId} order by daId")
    12. public List<DeliveryAddress> listDeliveryAddressByUserId(String userId);
    13. @Select("select * from deliveryAddress where daId=#{daId}")
    14. public DeliveryAddress getDeliveryAddressById(Integer daId);
    15. @Insert("insert into deliveryAddress values(null,#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    16. public int saveDeliveryAddress(DeliveryAddress deliveryAddress);
    17. @Update("update deliveryAddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address} where daId=#{daId}")
    18. public int updateDeliveryAddress(DeliveryAddress deliveryAddress);
    19. @Delete("delete from deliveryAddress where daId=#{daId}")
    20. public int removeDeliveryAddress(Integer daId);
    21. }

    4.2.1.4.Food

    1. package com.neusoft.elmboot.mapper;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import org.apache.ibatis.annotations.Select;
    5. import com.neusoft.elmboot.po.Food;
    6. @Mapper
    7. public interface FoodMapper {
    8. @Select("select * from food where businessId=#{businessId} order by foodId")
    9. public List<Food> listFoodByBusinessId(Integer businessId);
    10. @Select("select * from food where foodId=#{foodId}")
    11. public Food getFoodById(Integer foodId);
    12. }

    4.2.1.5.OrderDetailet

    1. package com.neusoft.elmboot.mapper;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import com.neusoft.elmboot.po.OrderDetailet;
    5. @Mapper
    6. public interface OrderDetailetMapper {
    7. public int saveOrderDetailetBatch(List<OrderDetailet> list);
    8. public List<OrderDetailet> listOrderDetailetByOrderId(Integer orderOd);
    9. }
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    4. <mapper namespace="com.neusoft.elmboot.mapper.OrderDetailetMapper">
    5. <insert id="saveOrderDetailetBatch" parameterType="OrderDetailet">
    6. insert into orderDetailet(orderId,foodId,quantity) values
    7. <foreach collection="list" item="od" separator=",">
    8. (#{od.orderId},#{od.foodId},#{od.quantity})
    9. </foreach>
    10. </insert>
    11. <resultMap type="OrderDetailet" id="orderDetailetResultMap">
    12. <id column="odId" property="odId"/>
    13. <result column="orderId" property="orderId"/>
    14. <result column="foodId" property="foodId"/>
    15. <result column="quantity" property="quantity"/>
    16. <association property="food" javaType="Food"
    17. select="com.neusoft.elmboot.mapper.FoodMapper.getFoodById" column="foodId"/>
    18. </resultMap>
    19. <select id="listOrderDetailetByOrderId" parameterType="Integer" resultMap="orderDetailetResultMap">
    20. select * from orderDetailet where orderId=#{orderId}
    21. </select>
    22. </mapper>

    4.2.1.6.Orders

    1. package com.neusoft.elmboot.mapper;
    2. import org.apache.ibatis.annotations.Insert;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import org.apache.ibatis.annotations.Select;
    5. import com.neusoft.elmboot.po.User;
    6. @Mapper
    7. public interface UserMapper {
    8. @Select("select * from user where userId=#{userId} and password=#{password}")
    9. public User getUserByIdByPass(User user);
    10. @Select("select count(*) from user where userId=#{userId}")
    11. public int getUserById(String userId);
    12. @Insert("insert into user values(#{userId},#{password},#{userName},#{userSex},null,1)")
    13. public int saveUser(User user);
    14. }
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    4. <mapper namespace="com.neusoft.elmboot.mapper.OrdersMapper">
    5. <resultMap type="Orders" id="ordersResultMap">
    6. <id column="orderId" property="orderId"/>
    7. <result column="userId" property="userId"/>
    8. <result column="businessId" property="businessId"/>
    9. <result column="orderDate" property="orderDate"/>
    10. <result column="orderTotal" property="orderTotal"/>
    11. <result column="daId" property="daId"/>
    12. <result column="orderState" property="orderState"/>
    13. <association property="business" javaType="Business"
    14. select="com.neusoft.elmboot.mapper.BusinessMapper.getBusinessById" column="businessId"/>
    15. <collection property="list" ofType="OrderDetailet"
    16. select="com.neusoft.elmboot.mapper.OrderDetailetMapper.listOrderDetailetByOrderId" column="orderId"/>
    17. </resultMap>
    18. <select id="getOrdersById" parameterType="Integer" resultMap="ordersResultMap">
    19. select * from orders where orderId=#{orderId}
    20. </select>
    21. <select id="listOrdersByUserId" parameterType="String" resultMap="ordersResultMap">
    22. select * from orders where userId=#{userId} order by orderId
    23. </select>
    24. </mapper>

    4.2.1.7.User

    1. package com.neusoft.elmboot.mapper;
    2. import org.apache.ibatis.annotations.Insert;
    3. import org.apache.ibatis.annotations.Mapper;
    4. import org.apache.ibatis.annotations.Select;
    5. import com.neusoft.elmboot.po.User;
    6. @Mapper
    7. public interface UserMapper {
    8. @Select("select * from user where userId=#{userId} and password=#{password}")
    9. public User getUserByIdByPass(User user);
    10. @Select("select count(*) from user where userId=#{userId}")
    11. public int getUserById(String userId);
    12. @Insert("insert into user values(#{userId},#{password},#{userName},#{userSex},null,1)")
    13. public int saveUser(User user);
    14. }

    4.2.2.Service层代码

    4.2.2.1.Business

    1. package com.neusoft.elmboot.service;
    2. import java.util.List;
    3. import com.neusoft.elmboot.po.Business;
    4. public interface BusinessService {
    5. public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);
    6. public Business getBusinessById(Integer businessId);
    7. }
    1. package com.neusoft.elmboot.service.impl;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Service;
    5. import com.neusoft.elmboot.mapper.BusinessMapper;
    6. import com.neusoft.elmboot.po.Business;
    7. import com.neusoft.elmboot.service.BusinessService;
    8. @Service
    9. public class BusinessServiceImpl implements BusinessService{
    10. @Autowired
    11. private BusinessMapper businessMapper;
    12. @Override
    13. public List<Business> listBusinessByOrderTypeId(Integer orderTypeId) {
    14. return businessMapper.listBusinessByOrderTypeId(orderTypeId);
    15. }
    16. @Override
    17. public Business getBusinessById(Integer businessId) {
    18. return businessMapper.getBusinessById(businessId);
    19. }
    20. }

    4.2.2.2.Cart

    1. package com.neusoft.elmboot.service;
    2. import java.util.List;
    3. import com.neusoft.elmboot.po.Cart;
    4. public interface CartService {
    5. public List<Cart> listCart(Cart cart);
    6. public int saveCart(Cart cart);
    7. public int updateCart(Cart cart);
    8. public int removeCart(Cart cart);
    9. }
    1. package com.neusoft.elmboot.service.impl;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Service;
    5. import com.neusoft.elmboot.mapper.CartMapper;
    6. import com.neusoft.elmboot.po.Cart;
    7. import com.neusoft.elmboot.service.CartService;
    8. @Service
    9. public class CartServiceImpl implements CartService{
    10. @Autowired
    11. private CartMapper cartMapper;
    12. @Override
    13. public List<Cart> listCart(Cart cart) {
    14. return cartMapper.listCart(cart);
    15. }
    16. @Override
    17. public int saveCart(Cart cart) {
    18. return cartMapper.saveCart(cart);
    19. }
    20. @Override
    21. public int updateCart(Cart cart) {
    22. return cartMapper.updateCart(cart);
    23. }
    24. @Override
    25. public int removeCart(Cart cart) {
    26. return cartMapper.removeCart(cart);
    27. }
    28. }

    4.2.2.3.DeliveryAddress

    1. package com.neusoft.elmboot.service;
    2. import java.util.List;
    3. import com.neusoft.elmboot.po.DeliveryAddress;
    4. public interface DeliveryAddressService {
    5. public List<DeliveryAddress> listDeliveryAddressByUserId(String userId);
    6. public DeliveryAddress getDeliveryAddressById(Integer daId);
    7. public int saveDeliveryAddress(DeliveryAddress deliveryAddress);
    8. public int updateDeliveryAddress(DeliveryAddress deliveryAddress);
    9. public int removeDeliveryAddress(Integer daId);
    10. }
    1. package com.neusoft.elmboot.service.impl;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Service;
    5. import com.neusoft.elmboot.mapper.DeliveryAddressMapper;
    6. import com.neusoft.elmboot.po.DeliveryAddress;
    7. import com.neusoft.elmboot.service.DeliveryAddressService;
    8. @Service
    9. public class DeliveryAddressServiceImpl implements DeliveryAddressService{
    10. @Autowired
    11. private DeliveryAddressMapper deliveryAddressMapper;
    12. @Override
    13. public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
    14. return deliveryAddressMapper.listDeliveryAddressByUserId(userId);
    15. }
    16. @Override
    17. public DeliveryAddress getDeliveryAddressById(Integer daId) {
    18. return deliveryAddressMapper.getDeliveryAddressById(daId);
    19. }
    20. @Override
    21. public int saveDeliveryAddress(DeliveryAddress deliveryAddress) {
    22. return deliveryAddressMapper.saveDeliveryAddress(deliveryAddress);
    23. }
    24. @Override
    25. public int updateDeliveryAddress(DeliveryAddress deliveryAddress) {
    26. return deliveryAddressMapper.updateDeliveryAddress(deliveryAddress);
    27. }
    28. @Override
    29. public int removeDeliveryAddress(Integer daId) {
    30. return deliveryAddressMapper.removeDeliveryAddress(daId);
    31. }
    32. }

    4.2.2.4.Food

    1. package com.neusoft.elmboot.service;
    2. import java.util.List;
    3. import com.neusoft.elmboot.po.Food;
    4. public interface FoodService {
    5. public List<Food> listFoodByBusinessId(Integer businessId);
    6. }
    1. package com.neusoft.elmboot.service.impl;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Service;
    5. import com.neusoft.elmboot.mapper.FoodMapper;
    6. import com.neusoft.elmboot.po.Food;
    7. import com.neusoft.elmboot.service.FoodService;
    8. @Service
    9. public class FoodServiceImpl implements FoodService{
    10. @Autowired
    11. private FoodMapper foodMapper;
    12. @Override
    13. public List<Food> listFoodByBusinessId(Integer businessId) {
    14. return foodMapper.listFoodByBusinessId(businessId);
    15. }
    16. }

    4.2.2.5.Orders

    1. package com.neusoft.elmboot.service;
    2. import java.util.List;
    3. import com.neusoft.elmboot.po.Orders;
    4. public interface OrdersService {
    5. public int createOrders(Orders orders);
    6. public Orders getOrdersById(Integer orderId);
    7. public List<Orders> listOrdersByUserId(String userId);
    8. }
    1. package com.neusoft.elmboot.service.impl;
    2. import java.util.ArrayList;
    3. import java.util.List;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Service;
    6. import org.springframework.transaction.annotation.Transactional;
    7. import com.neusoft.elmboot.mapper.CartMapper;
    8. import com.neusoft.elmboot.mapper.OrderDetailetMapper;
    9. import com.neusoft.elmboot.mapper.OrdersMapper;
    10. import com.neusoft.elmboot.po.Cart;
    11. import com.neusoft.elmboot.po.OrderDetailet;
    12. import com.neusoft.elmboot.po.Orders;
    13. import com.neusoft.elmboot.service.OrdersService;
    14. import com.neusoft.elmboot.util.CommonUtil;
    15. @Service
    16. public class OrdersServiceImpl implements OrdersService{
    17. @Autowired
    18. private CartMapper cartMapper;
    19. @Autowired
    20. private OrdersMapper ordersMapper;
    21. @Autowired
    22. private OrderDetailetMapper orderDetailetMapper;
    23. @Override
    24. @Transactional
    25. public int createOrders(Orders orders) {
    26. //1、查询当前用户购物车中当前商家的所有食品
    27. Cart cart = new Cart();
    28. cart.setUserId(orders.getUserId());
    29. cart.setBusinessId(orders.getBusinessId());
    30. List<Cart> cartList = cartMapper.listCart(cart);
    31. //2、创建订单(返回生成的订单编号)
    32. orders.setOrderDate(CommonUtil.getCurrentDate());
    33. ordersMapper.saveOrders(orders);
    34. int orderId = orders.getOrderId();
    35. //3、批量添加订单明细
    36. List<OrderDetailet> list = new ArrayList<>();
    37. for(Cart c : cartList) {
    38. OrderDetailet od = new OrderDetailet();
    39. od.setOrderId(orderId);
    40. od.setFoodId(c.getFoodId());
    41. od.setQuantity(c.getQuantity());
    42. list.add(od);
    43. }
    44. orderDetailetMapper.saveOrderDetailetBatch(list);
    45. //4、从购物车表中删除相关食品信息
    46. cartMapper.removeCart(cart);
    47. return orderId;
    48. }
    49. @Override
    50. public Orders getOrdersById(Integer orderId) {
    51. return ordersMapper.getOrdersById(orderId);
    52. }
    53. @Override
    54. public List<Orders> listOrdersByUserId(String userId){
    55. return ordersMapper.listOrdersByUserId(userId);
    56. }
    57. }

    4.2.2.6.user

    1. package com.neusoft.elmboot.service;
    2. import com.neusoft.elmboot.po.User;
    3. public interface UserService {
    4. public User getUserByIdByPass(User user);
    5. public int getUserById(String userId);
    6. public int saveUser(User user);
    7. }
    1. package com.neusoft.elmboot.service.impl;
    2. import org.springframework.beans.factory.annotation.Autowired;
    3. import org.springframework.stereotype.Service;
    4. import com.neusoft.elmboot.mapper.UserMapper;
    5. import com.neusoft.elmboot.po.User;
    6. import com.neusoft.elmboot.service.UserService;
    7. @Service
    8. public class UserServiceImpl implements UserService{
    9. @Autowired
    10. private UserMapper userMapper;
    11. @Override
    12. public User getUserByIdByPass(User user) {
    13. return userMapper.getUserByIdByPass(user);
    14. }
    15. @Override
    16. public int getUserById(String userId) {
    17. return userMapper.getUserById(userId);
    18. }
    19. @Override
    20. public int saveUser(User user) {
    21. return userMapper.saveUser(user);
    22. }
    23. }

    4.2.3.Controller层代码

    4.2.3.1.Business

    1. package com.neusoft.elmboot.controller;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. import com.neusoft.elmboot.po.Business;
    7. import com.neusoft.elmboot.service.BusinessService;
    8. @RestController
    9. @RequestMapping("/BusinessController")
    10. public class BusinessController {
    11. @Autowired
    12. private BusinessService businessService;
    13. @RequestMapping("/listBusinessByOrderTypeId")
    14. public List<Business> listBusinessByOrderTypeId(Business business) throws Exception{
    15. return businessService.listBusinessByOrderTypeId(business.getOrderTypeId());
    16. }
    17. @RequestMapping("/getBusinessById")
    18. public Business getBusinessById(Business business) throws Exception{
    19. return businessService.getBusinessById(business.getBusinessId());
    20. }
    21. }

    4.2.3.2.Cart

    1. package com.neusoft.elmboot.controller;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. import com.neusoft.elmboot.po.Cart;
    7. import com.neusoft.elmboot.service.CartService;
    8. @RestController
    9. @RequestMapping("/CartController")
    10. public class CartController {
    11. @Autowired
    12. private CartService cartService;
    13. @RequestMapping("/listCart")
    14. public List<Cart> listCart(Cart cart) throws Exception{
    15. return cartService.listCart(cart);
    16. }
    17. @RequestMapping("/saveCart")
    18. public int saveCart(Cart cart) throws Exception{
    19. return cartService.saveCart(cart);
    20. }
    21. @RequestMapping("/updateCart")
    22. public int updateCart(Cart cart) throws Exception{
    23. return cartService.updateCart(cart);
    24. }
    25. @RequestMapping("/removeCart")
    26. public int removeCart(Cart cart) throws Exception{
    27. return cartService.removeCart(cart);
    28. }
    29. }

    4.2.3.3.DeliveryAddress

    1. package com.neusoft.elmboot.controller;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. import com.neusoft.elmboot.po.DeliveryAddress;
    7. import com.neusoft.elmboot.service.DeliveryAddressService;
    8. @RestController
    9. @RequestMapping("/DeliveryAddressController")
    10. public class DeliveryAddressController {
    11. @Autowired
    12. private DeliveryAddressService deliveryAddressService;
    13. @RequestMapping("/listDeliveryAddressByUserId")
    14. public List<DeliveryAddress> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress) throws Exception{
    15. return deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId());
    16. }
    17. @RequestMapping("/getDeliveryAddressById")
    18. public DeliveryAddress getDeliveryAddressById(DeliveryAddress deliveryAddress) throws Exception{
    19. return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
    20. }
    21. @RequestMapping("/saveDeliveryAddress")
    22. public int saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
    23. return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
    24. }
    25. @RequestMapping("/updateDeliveryAddress")
    26. public int updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
    27. return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
    28. }
    29. @RequestMapping("/removeDeliveryAddress")
    30. public int removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
    31. return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
    32. }
    33. }

    4.2.3.4.Food

    1. package com.neusoft.elmboot.controller;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. import com.neusoft.elmboot.po.Food;
    7. import com.neusoft.elmboot.service.FoodService;
    8. @RestController
    9. @RequestMapping("/FoodController")
    10. public class FoodController {
    11. @Autowired
    12. private FoodService foodService;
    13. @RequestMapping("/listFoodByBusinessId")
    14. public List<Food> listFoodByBusinessId(Food food) throws Exception{
    15. return foodService.listFoodByBusinessId(food.getBusinessId());
    16. }
    17. }

    4.2.3.5.Orders

    1. package com.neusoft.elmboot.controller;
    2. import java.util.List;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.RestController;
    6. import com.neusoft.elmboot.po.Orders;
    7. import com.neusoft.elmboot.service.OrdersService;
    8. @RestController
    9. @RequestMapping("/OrdersController")
    10. public class OrdersController {
    11. @Autowired
    12. private OrdersService ordersService;
    13. @RequestMapping("/createOrders")
    14. public int createOrders(Orders orders) throws Exception{
    15. return ordersService.createOrders(orders);
    16. }
    17. @RequestMapping("/getOrdersById")
    18. public Orders getOrdersById(Orders orders) throws Exception{
    19. return ordersService.getOrdersById(orders.getOrderId());
    20. }
    21. @RequestMapping("/listOrdersByUserId")
    22. public List<Orders> listOrdersByUserId(Orders orders) throws Exception{
    23. return ordersService.listOrdersByUserId(orders.getUserId());
    24. }
    25. }

    4.2.3.7.user

    1. package com.neusoft.elmboot.controller;
    2. import org.springframework.beans.factory.annotation.Autowired;
    3. import org.springframework.web.bind.annotation.RequestMapping;
    4. import org.springframework.web.bind.annotation.RestController;
    5. import com.neusoft.elmboot.po.User;
    6. import com.neusoft.elmboot.service.UserService;
    7. @RestController
    8. @RequestMapping("/UserController")
    9. public class UserController {
    10. @Autowired
    11. private UserService userService;
    12. @RequestMapping("/getUserByIdByPass")
    13. public User getUserByIdByPass(User user) throws Exception{
    14. return userService.getUserByIdByPass(user);
    15. }
    16. @RequestMapping("/getUserById")
    17. public int getUserById(User user) throws Exception{
    18. return userService.getUserById(user.getUserId());
    19. }
    20. @RequestMapping("/saveUser")
    21. public int saveUser(User user) throws Exception{
    22. return userService.saveUser(user);
    23. }
    24. }

    4.3.前端代码

    代码地址: https://gitee.com/null_688_6639/elmproject

    4.3.1.Index组件

    注意点:

    1. 修改图片路径,包括css中背景图片路径
    2. style中添加scoped。
    3. 将静态工程中的 icon.css内容添加到style中。
  1. <template>
  2. <div class="wrapper">
  3. <!-- header部分 -->
  4. <header>
  5. <div class="icon-location-box">
  6. <div class="icon-location"></div>
  7. </div>
  8. <div class="location-text">沈阳市规划大厦<i class="fa fa-caret-down"></i></div>
  9. </header>
  10. <!-- search部分 -->
  11. <!--
  12. 搜索框部分(此块与search-fixed-top块宽度高度一致,用于当
  13. search-fixed-top块固定后,挡住下面块不要窜上去)
  14. -->
  15. <div class="search">
  16. <!-- 当滚动条超过上面的定位块时,search-fixed-top块变成固定在顶部。 -->
  17. <div class="search-fixed-top" ref="fixedBox">
  18. <!-- 搜索框部分中间的白框 -->
  19. <div class="search-box">
  20. <i class="fa fa-search"></i>搜索饿了么商家、商品名称
  21. </div>
  22. </div>
  23. </div>
  24. <!-- 点餐分类部分 -->
  25. <ul class="foodtype">
  26. <li @click="toBusinessList(1)">
  27. <img src="../assets/dcfl01.png">
  28. <p>美食</p>
  29. </li>
  30. <li @click="toBusinessList(2)">
  31. <img src="../assets/dcfl02.png">
  32. <p>早餐</p>
  33. </li>
  34. <li @click="toBusinessList(3)">
  35. <img src="../assets/dcfl03.png">
  36. <p>跑腿代购</p>
  37. </li>
  38. <li @click="toBusinessList(4)">
  39. <img src="../assets/dcfl04.png">
  40. <p>汉堡披萨</p>
  41. </li>
  42. <li @click="toBusinessList(5)">
  43. <img src="../assets/dcfl05.png">
  44. <p>甜品饮品</p>
  45. </li>
  46. <li @click="toBusinessList(6)">
  47. <img src="../assets/dcfl06.png">
  48. <p>速食简餐</p>
  49. </li>
  50. <li @click="toBusinessList(7)">
  51. <img src="../assets/dcfl07.png">
  52. <p>地方小吃</p>
  53. </li>
  54. <li @click="toBusinessList(8)">
  55. <img src="../assets/dcfl08.png">
  56. <p>米粉面馆</p>
  57. </li>
  58. <li @click="toBusinessList(9)">
  59. <img src="../assets/dcfl09.png">
  60. <p>包子粥铺</p>
  61. </li>
  62. <li @click="toBusinessList(10)">
  63. <img src="../assets/dcfl10.png">
  64. <p>炸鸡炸串</p>
  65. </li>
  66. </ul>
  67. <!-- 横幅广告部分(注意:此处有背景图片) -->
  68. <div class="banner">
  69. <h3>品质套餐</h3>
  70. <p>搭配齐全吃得好</p>
  71. <a>立即抢购 &gt;</a>
  72. </div>
  73. <!-- 超级会员部分 -->
  74. <div class="supermember">
  75. <div class="left">
  76. <img src="../assets/super_member.png">
  77. <h3>超级会员</h3>
  78. <p>&#8226; 每月享超值权益</p>
  79. </div>
  80. <div class="right">
  81. 立即开通 &gt;
  82. </div>
  83. </div>
  84. <!-- 推荐商家部分 -->
  85. <div class="recommend">
  86. <div class="recommend-line"></div>
  87. <p>推荐商家</p>
  88. <div class="recommend-line"></div>
  89. </div>
  90. <!-- 推荐方式部分 -->
  91. <ul class="recommendtype">
  92. <li>综合排序<i class="fa fa-caret-down"></i></li>
  93. <li>距离最近</li>
  94. <li>销量最高</li>
  95. <li>筛选<i class="fa fa-filter"></i></li>
  96. </ul>
  97. <!-- 推荐商家列表部分 -->
  98. <ul class="business">
  99. <li>
  100. <img src="../assets/sj01.png">
  101. <div class="business-info">
  102. <div class="business-info-h">
  103. <h3>万家饺子(软件园E18店)</h3>
  104. <div class="business-info-like">&#8226;</div>
  105. </div>
  106. <div class="business-info-star">
  107. <div class="business-info-star-left">
  108. <i class="fa fa-star"></i>
  109. <i class="fa fa-star"></i>
  110. <i class="fa fa-star"></i>
  111. <i class="fa fa-star"></i>
  112. <i class="fa fa-star"></i>
  113. <p>4.9 月售345单</p>
  114. </div>
  115. <div class="business-info-star-right">
  116. 蜂鸟专送
  117. </div>
  118. </div>
  119. <div class="business-info-delivery">
  120. <p>&#165;15起送 | &#165;3配送</p>
  121. <p>3.22km | 30分钟</p>
  122. </div>
  123. <div class="business-info-explain">
  124. <div>各种饺子</div>
  125. </div>
  126. <div class="business-info-promotion">
  127. <div class="business-info-promotion-left">
  128. <div class="business-info-promotion-left-incon"></div>
  129. <p>饿了么新用户首单立减9元</p>
  130. </div>
  131. <div class="business-info-promotion-right">
  132. <p>2个活动</p>
  133. <i class="fa fa-caret-down"></i>
  134. </div>
  135. </div>
  136. <div class="business-info-promotion">
  137. <div class="business-info-promotion-left">
  138. <div class="business-info-promotion-left-incon" style="background-color: #F1884F;"></div>
  139. <p>特价商品5元起</p>
  140. </div>
  141. </div>
  142. </div>
  143. </li>
  144. <li>
  145. <img src="../assets/sj02.png">
  146. <div class="business-info">
  147. <div class="business-info-h">
  148. <h3>小锅饭豆腐馆(全运店)</h3>
  149. <div class="business-info-like">&#8226;</div>
  150. </div>
  151. <div class="business-info-star">
  152. <div class="business-info-star-left">
  153. <i class="fa fa-star"></i>
  154. <i class="fa fa-star"></i>
  155. <i class="fa fa-star"></i>
  156. <i class="fa fa-star"></i>
  157. <i class="fa fa-star"></i>
  158. <p>4.9 月售345单</p>
  159. </div>
  160. <div class="business-info-star-right">
  161. 蜂鸟专送
  162. </div>
  163. </div>
  164. <div class="business-info-delivery">
  165. <p>&#165;15起送 | &#165;3配送</p>
  166. <p>3.22km | 30分钟</p>
  167. </div>
  168. <div class="business-info-explain">
  169. <div>各种饺子</div>
  170. </div>
  171. <div class="business-info-promotion">
  172. <div class="business-info-promotion-left">
  173. <div class="business-info-promotion-left-incon"></div>
  174. <p>饿了么新用户首单立减9元</p>
  175. </div>
  176. <div class="business-info-promotion-right">
  177. <p>2个活动</p>
  178. <i class="fa fa-caret-down"></i>
  179. </div>
  180. </div>
  181. <div class="business-info-promotion">
  182. <div class="business-info-promotion-left">
  183. <div class="business-info-promotion-left-incon"></div>
  184. <p>特价商品5元起</p>
  185. </div>
  186. </div>
  187. </div>
  188. </li>
  189. <li>
  190. <img src="../assets/sj03.png">
  191. <div class="business-info">
  192. <div class="business-info-h">
  193. <h3>麦当劳麦乐送(全运路店)</h3>
  194. <div class="business-info-like">&#8226;</div>
  195. </div>
  196. <div class="business-info-star">
  197. <div class="business-info-star-left">
  198. <i class="fa fa-star"></i>
  199. <i class="fa fa-star"></i>
  200. <i class="fa fa-star"></i>
  201. <i class="fa fa-star"></i>
  202. <i class="fa fa-star"></i>
  203. <p>4.9 月售345单</p>
  204. </div>
  205. <div class="business-info-star-right">
  206. 蜂鸟专送
  207. </div>
  208. </div>
  209. <div class="business-info-delivery">
  210. <p>&#165;15起送 | &#165;3配送</p>
  211. <p>3.22km | 30分钟</p>
  212. </div>
  213. <div class="business-info-explain">
  214. <div>各种饺子</div>
  215. </div>
  216. <div class="business-info-promotion">
  217. <div class="business-info-promotion-left">
  218. <div class="business-info-promotion-left-incon"></div>
  219. <p>饿了么新用户首单立减9元</p>
  220. </div>
  221. <div class="business-info-promotion-right">
  222. <p>2个活动</p>
  223. <i class="fa fa-caret-down"></i>
  224. </div>
  225. </div>
  226. <div class="business-info-promotion">
  227. <div class="business-info-promotion-left">
  228. <div class="business-info-promotion-left-incon"></div>
  229. <p>特价商品5元起</p>
  230. </div>
  231. </div>
  232. </div>
  233. </li>
  234. <li>
  235. <img src="../assets/sj04.png">
  236. <div class="business-info">
  237. <div class="business-info-h">
  238. <h3>米村拌饭(浑南店)</h3>
  239. <div class="business-info-like">&#8226;</div>
  240. </div>
  241. <div class="business-info-star">
  242. <div class="business-info-star-left">
  243. <i class="fa fa-star"></i>
  244. <i class="fa fa-star"></i>
  245. <i class="fa fa-star"></i>
  246. <i class="fa fa-star"></i>
  247. <i class="fa fa-star"></i>
  248. <p>4.9 月售345单</p>
  249. </div>
  250. <div class="business-info-star-right">
  251. 蜂鸟专送
  252. </div>
  253. </div>
  254. <div class="business-info-delivery">
  255. <p>&#165;15起送 | &#165;3配送</p>
  256. <p>3.22km | 30分钟</p>
  257. </div>
  258. <div class="business-info-explain">
  259. <div>各种饺子</div>
  260. </div>
  261. <div class="business-info-promotion">
  262. <div class="business-info-promotion-left">
  263. <div class="business-info-promotion-left-incon"></div>
  264. <p>饿了么新用户首单立减9元</p>
  265. </div>
  266. <div class="business-info-promotion-right">
  267. <p>2个活动</p>
  268. <i class="fa fa-caret-down"></i>
  269. </div>
  270. </div>
  271. <div class="business-info-promotion">
  272. <div class="business-info-promotion-left">
  273. <div class="business-info-promotion-left-incon"></div>
  274. <p>特价商品5元起</p>
  275. </div>
  276. </div>
  277. </div>
  278. </li>
  279. <li>
  280. <img src="../assets/sj05.png">
  281. <div class="business-info">
  282. <div class="business-info-h">
  283. <h3>申记串道(中海康城店)</h3>
  284. <div class="business-info-like">&#8226;</div>
  285. </div>
  286. <div class="business-info-star">
  287. <div class="business-info-star-left">
  288. <i class="fa fa-star"></i>
  289. <i class="fa fa-star"></i>
  290. <i class="fa fa-star"></i>
  291. <i class="fa fa-star"></i>
  292. <i class="fa fa-star"></i>
  293. <p>4.9 月售345单</p>
  294. </div>
  295. <div class="business-info-star-right">
  296. 蜂鸟专送
  297. </div>
  298. </div>
  299. <div class="business-info-delivery">
  300. <p>&#165;15起送 | &#165;3配送</p>
  301. <p>3.22km | 30分钟</p>
  302. </div>
  303. <div class="business-info-explain">
  304. <div>各种饺子</div>
  305. </div>
  306. <div class="business-info-promotion">
  307. <div class="business-info-promotion-left">
  308. <div class="business-info-promotion-left-incon"></div>
  309. <p>饿了么新用户首单立减9元</p>
  310. </div>
  311. <div class="business-info-promotion-right">
  312. <p>2个活动</p>
  313. <i class="fa fa-caret-down"></i>
  314. </div>
  315. </div>
  316. <div class="business-info-promotion">
  317. <div class="business-info-promotion-left">
  318. <div class="business-info-promotion-left-incon"></div>
  319. <p>特价商品5元起</p>
  320. </div>
  321. </div>
  322. </div>
  323. </li>
  324. </ul>
  325. <!-- 底部菜单部分 -->
  326. <Footer></Footer>
  327. </div>
  328. </template>
  329. <script>
  330. //导入共通组件
  331. import Footer from '../components/Footer.vue';
  332. export default {
  333. name: 'Index',
  334. mounted() {
  335. document.onscroll = ()=> {
  336. //获取滚动条位置
  337. let s1 = document.documentElement.scrollTop;
  338. let s2 = document.body.scrollTop;
  339. let scroll = s1 == 0 ? s2 : s1;
  340. //获取视口宽度
  341. let width = document.documentElement.clientWidth;
  342. //获取顶部固定块
  343. let search = this.$refs.fixedBox;
  344. //判断滚动条超过视口宽度的12%时,搜索块变固定定位
  345. if (scroll > width * 0.12) {
  346. search.style.position = 'fixed';
  347. search.style.left = '0';
  348. search.style.top = '0';
  349. } else {
  350. search.style.position = 'static';
  351. }
  352. }
  353. },
  354. destroyed() {
  355. //当切换到其他组件时,就不需要document滚动条事件,所以将此事件去掉
  356. document.onscroll = null;
  357. },
  358. components:{
  359. Footer
  360. },
  361. methods:{
  362. toBusinessList(orderTypeId){
  363. this.$router.push({path:'/businessList',query:{orderTypeId:orderTypeId}});
  364. }
  365. }
  366. }
  367. </script>
  368. <style scoped>
  369. /****************** 总容器 ******************/
  370. .wrapper {
  371. width: 100%;
  372. height: 100%;
  373. }
  374. /****************** header ******************/
  375. .wrapper header {
  376. width: 100%;
  377. height: 12vw;
  378. background-color: #0097FF;
  379. display: flex;
  380. align-items: center;
  381. }
  382. .wrapper header .icon-location-box {
  383. width: 3.5vw;
  384. height: 3.5vw;
  385. margin: 0 1vw 0 3vw;
  386. }
  387. .wrapper header .location-text {
  388. font-size: 4.5vw;
  389. font-weight: 700;
  390. color: #fff;
  391. }
  392. .wrapper header .location-text .fa-caret-down {
  393. margin-left: 1vw;
  394. }
  395. /****************** search ******************/
  396. .wrapper .search {
  397. width: 100%;
  398. height: 13vw;
  399. }
  400. .wrapper .search .search-fixed-top {
  401. width: 100%;
  402. height: 13vw;
  403. background-color: #0097FF;
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. }
  408. .wrapper .search .search-fixed-top .search-box {
  409. width: 90%;
  410. height: 9vw;
  411. background-color: #fff;
  412. border-radius: 2px;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. font-size: 3.5vw;
  417. color: #AEAEAE;
  418. font-family: "宋体";
  419. /*此样式是让文本选中状态无效*/
  420. user-select: none;
  421. }
  422. .wrapper .search .search-fixed-top .search-box .fa-search {
  423. margin-right: 1vw;
  424. }
  425. /****************** 点餐分类部分 ******************/
  426. .wrapper .foodtype {
  427. width: 100%;
  428. height: 48vw;
  429. display: flex;
  430. flex-wrap: wrap;
  431. justify-content: space-around;
  432. /*要使用align-content。10个子元素将自动换行为两行,而且两行作为一个整体垂直居中*/
  433. align-content: center;
  434. }
  435. .wrapper .foodtype li {
  436. /*一共10个子元素,通过计算,子元素宽度在16.7 ~ 20 之间,才能保证换两行*/
  437. width: 18vw;
  438. height: 20vw;
  439. display: flex;
  440. /*弹性盒子主轴方向设为column,然后仍然是垂直水平方向居中*/
  441. flex-direction: column;
  442. justify-content: center;
  443. align-items: center;
  444. user-select: none;
  445. cursor: pointer;
  446. }
  447. .wrapper .foodtype li img {
  448. width: 12vw;
  449. /*视频讲解时高度设置为12vw,实际上设置为10.3vw更佳*/
  450. height: 10.3vw;
  451. }
  452. .wrapper .foodtype li p {
  453. font-size: 3.2vw;
  454. color: #666;
  455. }
  456. /****************** 横幅广告部分 ******************/
  457. .wrapper .banner {
  458. /**
  459. * 设置容器宽度95%,然后水平居中,这样两边留白;
  460. * 这里不能用padding,因为背景图片也会覆盖padding
  461. */
  462. width: 95%;
  463. margin: 0 auto;
  464. height: 29vw;
  465. /*此三个样式组合,可以保证背景图片充满整个容器*/
  466. background-image: url(../assets/index_banner.png);
  467. background-repeat: no-repeat;
  468. background-size: cover;
  469. box-sizing: border-box;
  470. padding: 2vw 6vw;
  471. }
  472. .wrapper .banner h3 {
  473. font-size: 4.2vw;
  474. margin-bottom: 1.2vw;
  475. }
  476. .wrapper .banner p {
  477. font-size: 3.4vw;
  478. color: #666;
  479. margin-bottom: 2.4vw;
  480. }
  481. .wrapper .banner a {
  482. font-size: 3vw;
  483. color: #C79060;
  484. font-weight: 700;
  485. }
  486. /****************** 超级会员部分 ******************/
  487. .wrapper .supermember {
  488. /*这里也设置容器宽度95%,不能用padding,因为背景色也会充满padding*/
  489. width: 95%;
  490. margin: 0 auto;
  491. height: 11.5vw;
  492. background-color: #FEEDC1;
  493. margin-top: 1.3vw;
  494. border-radius: 2px;
  495. color: #644F1B;
  496. display: flex;
  497. justify-content: space-between;
  498. align-items: center;
  499. }
  500. .wrapper .supermember .left {
  501. display: flex;
  502. align-items: center;
  503. margin-left: 4vw;
  504. user-select: none;
  505. }
  506. .wrapper .supermember .left img {
  507. width: 6vw;
  508. height: 6vw;
  509. margin-right: 2vw;
  510. }
  511. .wrapper .supermember .left h3 {
  512. font-size: 4vw;
  513. margin-right: 2vw;
  514. }
  515. .wrapper .supermember .left p {
  516. font-size: 3vw;
  517. }
  518. .wrapper .supermember .right {
  519. font-size: 3vw;
  520. margin-right: 4vw;
  521. cursor: pointer;
  522. }
  523. /****************** 推荐商家部分 ******************/
  524. .wrapper .recommend {
  525. width: 100%;
  526. height: 14vw;
  527. display: flex;
  528. justify-content: center;
  529. align-items: center;
  530. }
  531. .wrapper .recommend .recommend-line {
  532. width: 6vw;
  533. height: 0.2vw;
  534. background-color: #888;
  535. }
  536. .wrapper .recommend p {
  537. font-size: 4vw;
  538. margin: 0 4vw;
  539. }
  540. /****************** 推荐方式部分 ******************/
  541. .wrapper .recommendtype {
  542. width: 100%;
  543. height: 5vw;
  544. margin-bottom: 5vw;
  545. display: flex;
  546. justify-content: space-around;
  547. align-items: center;
  548. }
  549. .wrapper .recommendtype li {
  550. font-size: 3.5vw;
  551. color: #555;
  552. }
  553. /****************** 推荐商家列表部分 ******************/
  554. .wrapper .business {
  555. width: 100%;
  556. margin-bottom: 14vw;
  557. }
  558. .wrapper .business li {
  559. width: 100%;
  560. box-sizing: border-box;
  561. padding: 2.5vw;
  562. user-select: none;
  563. border-bottom: solid 1px #DDD;
  564. display: flex;
  565. }
  566. .wrapper .business li img {
  567. width: 18vw;
  568. height: 18vw;
  569. }
  570. .wrapper .business li .business-info {
  571. width: 100%;
  572. box-sizing: border-box;
  573. padding-left: 3vw;
  574. }
  575. .wrapper .business li .business-info .business-info-h {
  576. display: flex;
  577. justify-content: space-between;
  578. align-items: center;
  579. margin-bottom: 2vw;
  580. }
  581. .wrapper .business li .business-info .business-info-h h3 {
  582. font-size: 4vw;
  583. color: #333;
  584. }
  585. .wrapper .business li .business-info .business-info-h .business-info-like {
  586. width: 1.6vw;
  587. height: 3.4vw;
  588. background-color: #666;
  589. color: #fff;
  590. font-size: 4vw;
  591. margin-right: 4vw;
  592. display: flex;
  593. justify-content: center;
  594. align-items: center;
  595. }
  596. .wrapper .business li .business-info .business-info-star {
  597. display: flex;
  598. justify-content: space-between;
  599. align-items: center;
  600. margin-bottom: 2vw;
  601. font-size: 3.1vw;
  602. }
  603. .wrapper .business li .business-info .business-info-star .business-info-star-left {
  604. display: flex;
  605. align-items: center;
  606. }
  607. .wrapper .business li .business-info .business-info-star .business-info-star-left .fa-star {
  608. color: #FEC80E;
  609. margin-right: 0.5vw;
  610. }
  611. .wrapper .business li .business-info .business-info-star .business-info-star-left p {
  612. color: #666;
  613. margin-left: 1vw;
  614. }
  615. .wrapper .business li .business-info .business-info-star .business-info-star-right {
  616. background-color: #0097FF;
  617. color: #fff;
  618. font-size: 2.4vw;
  619. border-radius: 2px;
  620. padding: 0 0.6vw;
  621. }
  622. .wrapper .business li .business-info .business-info-delivery {
  623. display: flex;
  624. justify-content: space-between;
  625. align-items: center;
  626. margin-bottom: 2vw;
  627. color: #666;
  628. font-size: 3.1vw;
  629. }
  630. .wrapper .business li .business-info .business-info-explain {
  631. display: flex;
  632. align-items: center;
  633. margin-bottom: 3vw;
  634. }
  635. .wrapper .business li .business-info .business-info-explain div {
  636. border: solid 1px #DDD;
  637. font-size: 2.8vw;
  638. color: #666;
  639. border-radius: 3px;
  640. padding: 0 0.1vw;
  641. }
  642. .wrapper .business li .business-info .business-info-promotion {
  643. display: flex;
  644. justify-content: space-between;
  645. align-items: center;
  646. margin-bottom: 1.8vw;
  647. }
  648. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left {
  649. display: flex;
  650. align-items: center;
  651. }
  652. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left .business-info-promotion-left-incon {
  653. width: 4vw;
  654. height: 4vw;
  655. background-color: #70BC46;
  656. border-radius: 3px;
  657. font-size: 3vw;
  658. color: #fff;
  659. display: flex;
  660. justify-content: center;
  661. align-items: center;
  662. }
  663. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-left p {
  664. color: #666;
  665. font-size: 3vw;
  666. margin-left: 2vw;
  667. }
  668. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-right {
  669. display: flex;
  670. align-items: center;
  671. font-size: 2.5vw;
  672. color: #999;
  673. }
  674. .wrapper .business li .business-info .business-info-promotion .business-info-promotion-right p {
  675. margin-right: 2vw;
  676. }
  677. </style>

4.3.2.BusinessList组件

4.3.3.BusinessInfo组件

4.3.4.Order组件

4.3.5.Payment组件

4.3.6.UserAddress组件

4.3.7.AddUserAddress组件

4.3.8.EditUserAddress组件

4.3.9.OrderList组件

4.3.10.Login组件

4.3.11.Register组件

4.3.12.Footer共通组件