0
点赞
收藏
分享

微信扫一扫

瑞吉外卖-全网最全笔记-Day01

盖码范 2022-04-17 阅读 120

业务开发Day1-01-本章内容介绍

项目效果展示

登录界面
![VHRHB3OMOBTIY%F7QJ@@8GJ.png](https://img-blog.csdnimg.cn/img_convert/265b1edd67d79f674a8dae7b787131e6.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u4635ffed&margin=[object Object]&name=VHRHB3OMOBTIY%F7QJ@@8GJ.png&originHeight=779&originWidth=1859&originalType=binary&ratio=1&rotation=0&showTitle=false&size=528885&status=done&style=none&taskId=u6e582532-650c-40b3-a849-f7e39ecd0af&title=)
登录成功界面
![MIEHEKWN7EGNP6{W0KONW3F.png](https://img-blog.csdnimg.cn/img_convert/64d4eaa335a50cbcf4a8161e21bab0bb.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u5072449a&margin=[object Object]&name=MIEHEKWN7EGNP6{W0KONW3F.png&originHeight=975&originWidth=1877&originalType=binary&ratio=1&rotation=0&showTitle=false&size=497193&status=done&style=none&taskId=u725ae48a-d173-450e-b36b-9093e0a84f9&title=)

管理界面展示

  • 员工管理
  • 分类管理
  • 菜品管理
  • 套餐管理
  • 订单明细

请添加图片描述

前端开发使用HTML5技术(自适应屏幕大小功能)

请添加图片描述

目录

  • 软件开发整体介绍
  • 瑞吉外卖项目介绍
  • 开发环境搭建

业务开发Day1-02-软件开发整体介绍

  • 软件开发流程
  • 角色分工
  • 软件环境

软件开发流程

需求分析->设计->编码->测试->上线运维
请添加图片描述

角色分工

  • 项目经理
  • 产品经理
  • UI设计师
  • 架构师
  • 开发工程师
  • 测试工程师
  • 运维工程师
    请添加图片描述

软件环境

  • 开发环境
  • 测试环境
  • 生产环境

请添加图片描述

业务开发Day1-03-瑞吉外卖项目整体介绍

目录

  • 项目介绍
  • 产品原型展示
  • 技术选型
  • 功能架构
  • 角色

![6XG0R6(O[CW%YHMK_VI}E4L.png](https://img-blog.csdnimg.cn/img_convert/e9b1f8a7f14941d723a1e68bf981bd57.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u9b33ba69&margin=[object Object]&name=6XG0R6(O[CW%YHMK_VI}E4L.png&originHeight=943&originWidth=1919&originalType=binary&ratio=1&rotation=0&showTitle=false&size=118781&status=done&style=none&taskId=u3841da93-fc3c-452a-b3dc-b983dc7a8fe&title=)

项目介绍

本项目是专门为餐饮企业(餐厅、饭店)定制的一款软件产品,包括系统管理后台和移动端应用两部分。

  • 系统管理后台主要提功给餐饮企业内部员工使用(功能:对餐厅的菜品、套餐、订单等进行管理维护等)
  • 移动端应用主要提供给消费者使用(功能:在线浏览菜品、添加购物车、下单等)

产品原型展示

![L]$77P(OFP8FKN]19J0A0ER.png](https://img-blog.csdnimg.cn/img_convert/fae97d597e66c0708a177d84c7b8244a.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u418479fd&margin=[object Object]&name=L]$77P(OFP8FKN]19J0A0ER.png&originHeight=958&originWidth=1842&originalType=binary&ratio=1&rotation=0&showTitle=false&size=303805&status=done&style=none&taskId=u10b5b0da-8b85-4590-9315-428ff7919c1&title=)

技术选型

  • 用户层
  • 网关层
  • 应用层
  • 数据层
  • 以及使用到的工具

![6UM@I5Q[GPZW0(PG0L3U9.png](https://img-blog.csdnimg.cn/img_convert/9d190d0cbd3db5c6c3f8ccc8b101d26d.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u7d48fef1&margin=[object Object]&name=6UM@I5Q[GPZW0(PG0L3U9.png&originHeight=844&originWidth=1916&originalType=binary&ratio=1&rotation=0&showTitle=false&size=225352&status=done&style=none&taskId=u409e3e38-fe82-48f3-ba2f-2df758a1fe6&title=)

功能架构

  • 移动端前台
  • 系统管理后台
    请添加图片描述

角色

  • 后台系统管理员
  • 后台系统普通员工
  • C端用户

![{]0@A7JB82JH32~L3SK]9QJ.png](https://img-blog.csdnimg.cn/img_convert/68a29329629490a404e712a0b13f5005.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u3e5fa0d9&margin=[object Object]&name={]0@A7JB82JH32~L3SK]9QJ.png&originHeight=840&originWidth=1920&originalType=binary&ratio=1&rotation=0&showTitle=false&size=384007&status=done&style=none&taskId=u1f354c1e-7539-47f6-a470-8da09282cfd&title=)

业务开发Day1-04-开发环境搭建-数据库环境搭建

  1. 使用navicat(数据库可视化界面)创建对应的数据库,数据库名:reggie,字符集:utf8mb4

![image.png](https://img-blog.csdnimg.cn/img_convert/b108faf452361e301066b794d01d5b38.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=386&id=u0cd402ed&margin=[object Object]&name=image.png&originHeight=482&originWidth=544&originalType=binary&ratio=1&rotation=0&showTitle=false&size=15514&status=done&style=none&taskId=u63dc9386-bd04-4730-ab20-998320e0a33&title=&width=435.2)

  1. 操作步骤
  • 第一步:右键点击数据库再点击运行sql文件
  • 第二步:选择资料下载的位置,我的资料存储在D:\瑞吉外卖\资料\数据模型\db_reggie.sql,点击开始即可
  • 第三步:打开表,即可查看数据库中执行完sql文件的所有信息

![image.png](https://img-blog.csdnimg.cn/img_convert/f178ebafb2ee7016afdcb8679ac4a159.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=637&id=u9e52141f&margin=[object Object]&name=image.png&originHeight=796&originWidth=1192&originalType=binary&ratio=1&rotation=0&showTitle=false&size=129507&status=done&style=none&taskId=u92bed46f-f412-4c7e-8232-e51a3689a7e&title=&width=953.6)执行完sql文件对应的对象信息![image.png](https://img-blog.csdnimg.cn/img_convert/e4c3fea3532ecb02075be9293084ee8e.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=306&id=ud9acfc73&margin=[object Object]&name=image.png&originHeight=382&originWidth=648&originalType=binary&ratio=1&rotation=0&showTitle=false&size=37865&status=done&style=none&taskId=u35055c39-a198-4ec3-a95f-b5ad36bb0ab&title=&width=518.4)

业务开发Day1-05-开发环境搭建-maven项目环境搭建

创建maven项目

![image.png](https://img-blog.csdnimg.cn/img_convert/2ec455a2aa38e835b8fad5652cb76313.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=421&id=u14aa5d30&margin=[object Object]&name=image.png&originHeight=526&originWidth=676&originalType=binary&ratio=1&rotation=0&showTitle=false&size=51413&status=done&style=none&taskId=u7ff3002c-4885-4884-94c1-0252a5b78df&title=&width=540.8)

  • 点击next
    ![image.png](https://img-blog.csdnimg.cn/img_convert/3fb1f3beafa482b879d66d077d2b3307.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=671&id=u842d8e32&margin=[object Object]&name=image.png&originHeight=839&originWidth=1004&originalType=binary&ratio=1&rotation=0&showTitle=false&size=110313&status=done&style=none&taskId=ub7a8788c-3027-40a4-be74-fe18f3c51a0&title=&width=803.2)

  • 填写好项目相关信息后,点击finish
    ![image.png](https://img-blog.csdnimg.cn/img_convert/29567b138e6d4e71c195072930ff5f38.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=671&id=u88c3fb16&margin=[object Object]&name=image.png&originHeight=839&originWidth=1004&originalType=binary&ratio=1&rotation=0&showTitle=false&size=47139&status=done&style=none&taskId=u5d5d4811-d501-4f39-b68e-73d519278f3&title=&width=803.2)

改pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  
  <groupId>com.itzq</groupId>
  <artifactId>reggie_take_out</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--  lookup parent from repository  -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.5</version>
    <relativePath/>
  </parent>
  <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
  </properties>
  
  <!--  注入依赖  -->
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <scope>compile</scope>
    </dependency>
    <!--   mybatis依赖     -->
    <dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus-boot-starter</artifactId>
      <version>3.4.2</version>
    </dependency>
    <!--   lombok     -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.20</version>
    </dependency>
    <!--    将数据转为json对象    -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.76</version>
    </dependency>
    <!--    common-lang    -->
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
    </dependency>
    <!--    连接数据库依赖    -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
    </dependency>
    <!--    druid数据库连接池    -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid-spring-boot-starter</artifactId>
      <version>1.1.23</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.4.5</version>
      </plugin>
    </plugins>
  </build>
</project>

写YML

#端口号
server:
  port: 8080
spring:
  application:
    #服务名称
    name: reggie_take_out
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/reggie?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
      username: root
      password: root
mybatis-plus:
  configuration:
    #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      #主键策略:ASSIGN_ID(雪花算法)
      id-type: ASSIGN_ID

主启动

在java下新建主启动类,带上包名![image.png](https://img-blog.csdnimg.cn/img_convert/2305488245e8e9eb49e6940868a1d78d.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=181&id=u334899a9&margin=[object Object]&name=image.png&originHeight=226&originWidth=415&originalType=binary&ratio=1&rotation=0&showTitle=false&size=9980&status=done&style=none&taskId=ud5fcb8cb-162f-409b-b7b8-43cc76bc651&title=&width=332)

package com.itzq.reggie;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication
public class ReggieApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReggieApplication.class,args);
        log.info("项目启动成功。。。");
    }
}

将前端资源放入resources下

在磁盘中找到前端资源下的目录
![image.png](https://img-blog.csdnimg.cn/img_convert/39e4e28eb2cd8e95ceb087876392cef2.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=174&id=uc7c7f9fb&margin=[object Object]&name=image.png&originHeight=217&originWidth=738&originalType=binary&ratio=1&rotation=0&showTitle=false&size=15312&status=done&style=none&taskId=u5c611e86-edaa-4cd9-82fd-2489fab27d3&title=&width=590.4)
将目录放入resources下
![image.png](https://img-blog.csdnimg.cn/img_convert/ccd37e158a958e06adb4ba5953183ecf.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=106&id=u9b180dfb&margin=[object Object]&name=image.png&originHeight=132&originWidth=492&originalType=binary&ratio=1&rotation=0&showTitle=false&size=8363&status=done&style=none&taskId=u459bda02-14fb-43a9-b6e0-968aaad36a9&title=&width=393.6)

启动工程

项目启动成功![image.png](https://img-blog.csdnimg.cn/img_convert/974573626c731eac104b92078e681b44.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=338&id=u12f422b3&margin=[object Object]&name=image.png&originHeight=423&originWidth=1684&originalType=binary&ratio=1&rotation=0&showTitle=false&size=108845&status=done&style=none&taskId=u301d89f3-3bd1-4c28-859f-faeb0ad77b6&title=&width=1347.2)

访问路径 http://localhost:8080/backend/index.html ,出现无法访问,默认情况下我们只能访问static、template静态目录下的静态资源,此时我们可以通过配置类的方式来设置静态资源映射![image.png](https://img-blog.csdnimg.cn/img_convert/a94b358e14ed36b04a2333c18e6706f2.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=553&id=ubb81d5dd&margin=[object Object]&name=image.png&originHeight=691&originWidth=1224&originalType=binary&ratio=1&rotation=0&showTitle=false&size=36177&status=done&style=none&taskId=u69d46c77-32a2-4071-a44f-712cedfdf17&title=&width=979.2)

配置类设置静态资源映射

![image.png](https://img-blog.csdnimg.cn/img_convert/88fbb4cd4867cea571e04a2341e1e6d0.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=181&id=uf77bb75f&margin=[object Object]&name=image.png&originHeight=226&originWidth=415&originalType=binary&ratio=1&rotation=0&showTitle=false&size=9678&status=done&style=none&taskId=uae0777da-2dd4-4c3a-a571-d53305c64f9&title=&width=332)

通过继承WebMvcConfigurationSupport,重写addResourceHandlers方法来实现我们想要的功能

package com.itzq.reggie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    /**
     * 设置静态资源映射
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始进行静态资源映射。。。");
        //访问路径
        registry.addResourceHandler("/backend/**")
                //映射到真实的路径(映射的真实路径末尾必须添加斜杠`/`)
                .addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**")
                .addResourceLocations("classpath:/front/");
    }
}

重新启动工程!
浏览器访问地址:http://localhost:8080/backend/index.html,出现以下界面即配置成功,页面中请求出错是因为前端发送了一个ajax请求,而后端还没有写东西所以页面提示请求出错。![image.png](https://img-blog.csdnimg.cn/img_convert/7e92832313c49ce81b86d0632dfe4824.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=826&id=u728704b4&margin=[object Object]&name=image.png&originHeight=1033&originWidth=1869&originalType=binary&ratio=1&rotation=0&showTitle=false&size=101024&status=done&style=none&taskId=ucbc3db74-8a08-4d4c-a7ed-c1d6b5632cf&title=&width=1495.2)

业务开发Day1-06-后台系统登录功能-需求分析

需求分析

登录页面展示

访问路径:http://localhost:8080/backend/page/login/login.html
![image.png](https://img-blog.csdnimg.cn/img_convert/1ace1d81b947d33fd78f5ae72e8ec23b.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=722&id=u4d1419c5&margin=[object Object]&name=image.png&originHeight=903&originWidth=1699&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1228966&status=done&style=none&taskId=u2b6f01d2-7bb4-4709-ac4f-fd88462e35e&title=&width=1359.2)

数据库的密码通过MD5加密了,它的明文密码为123456
![IMPO[IC0A5TL_%KHP(9CK[7.png](https://img-blog.csdnimg.cn/img_convert/c16a431f46a884fcdcb47ca6e119111f.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=uadddfffb&margin=[object Object]&name=IMPO[IC0A5TL_%KHP(9CK[7.png&originHeight=880&originWidth=1798&originalType=binary&ratio=1&rotation=0&showTitle=false&size=108637&status=done&style=none&taskId=u3bc0d78e-bb04-497d-b4b7-0ee943b8654&title=)

输入正确的用户名和密码点击登录,按住f12,寻找到以下页面,可以看到请求路径跳转到地址为:localhost:8080/employee/login的页面,报404错误,因为后台系统还没有响应此请求的处理器,我们需要创建相关类来处理登录请求

业务开发Day1-07-后台系统登录功能-代码开发(创建controller,service,mapper,实体类

代码开发

创建controller,service,mapper,实体类

  1. 在reggie包下分别创建controller,service(在此包下再创建一个impl包),mapper,entity包
  2. 在entity包下创建Employee类
package com.itzq.reggie.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String username;

    private String name;

    private String password;

    private String phone;

    private String sex;

    private String idNumber;

    private Integer status;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    @TableField(fill = FieldFill.INSERT)
    private Long createUser;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateUser;

}
  1. 在mapper包下创建EmployeeMapper接口,并继承BaseMapper,添加@Mapper注解在该接口上
package com.itzq.reggie.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itzq.reggie.entity.Employee;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface EmployeeMapper extends BaseMapper<Employee> {
}

  1. 在service包下编写EmployeeService接口,并继承IService
package com.itzq.reggie.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.itzq.reggie.entity.Employee;

public interface EmployeeService extends IService<Employee> {
}

  1. 在Impl包下编写EmployeeServiceImpl类,并继承ServiceImpl类,实现EmployeeService接口
package com.itzq.reggie.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itzq.reggie.entity.Employee;
import com.itzq.reggie.mapper.EmployeeMapper;
import com.itzq.reggie.service.EmployeeService;
import org.springframework.stereotype.Service;

@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
}

  1. 在controller包下编写EmployeeController类
package com.itzq.reggie.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

}

业务开发Day1-08-后台系统登录功能-代码开发(导入通用返回结果类

导入通用结果类

![image.png](https://img-blog.csdnimg.cn/img_convert/c175ec511a1dda4ac2d6dc1044f017b8.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=110&id=u474db632&margin=[object Object]&name=image.png&originHeight=138&originWidth=1171&originalType=binary&ratio=1&rotation=0&showTitle=false&size=67957&status=done&style=none&taskId=ub88f7956-37dc-4382-ac5b-0b63aef93b5&title=&width=936.8)

在reggie包下创建一个子包为common,再在common包下创建一个R类

package com.itzq.reggie.common;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回结果,服务器响应的数据最终都会封装成此对象
 * @param <T>
 */
@Data
public class R<T> {

    private Integer code; //编码:1成功,0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> R<T> success(T object) {
        R<T> r = new R<T>();
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> R<T> error(String msg) {
        R r = new R();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public R<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}

业务开发Day1-09-后台系统登录功能-代码开发(梳理登录方法处理逻辑

代码开发以及梳理

给EmployeeController类添加一个login方法

  • @RequestBody 主要用于接收前端传递给后端的json字符串(请求体中的数据)
  • HttpServletRequest request作用:如果登录成功,将员工对应的id存到session一份,这样想获取一份登录用户的信息就可以随时获取出来
package com.itzq.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itzq.reggie.common.R;
import com.itzq.reggie.entity.Employee;
import com.itzq.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    /**
     * 员工登录
     * @param request
     * @param employee
     * @return
     */
    //@RequestBody 主要用于接收前端传递给后端的json字符串(请求体中的数据)
    //HttpServletRequest request作用:如果登录成功,将员工对应的id存到session一份,这样想获取一份登录用户的信息就可以随时获取出来
    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
        return null;
    }
}

在controller中创建登录方法

  1. 将页面提交的密码进行MD5加密处理
  2. 根据页面提交的用户名username查询数据库
  3. 如果没有查询到则返回登录失败结果
  4. 密码比对,如果不一致则返回登录结果
  5. 查看员工状态,如果已为禁用状态,则返回员工已禁用结果
  6. 登录成功,将员工id存入session并返回登录成功结果
    请添加图片描述

业务开发Day1-10-后台系统登录功能-代码开发(实现登录处理逻辑

编写代码实现逻辑

在EmployeeController类的login方法中添加代码实现登录处理逻辑

package com.itzq.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itzq.reggie.common.R;
import com.itzq.reggie.entity.Employee;
import com.itzq.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    /**
     * 员工登录
     * @param request
     * @param employee
     * @return
     */
    //@RequestBody 主要用于接收前端传递给后端的json字符串(请求体中的数据)
    //HttpServletRequest request作用:如果登录成功,将员工对应的id存到session一份,这样想获取一份登录用户的信息就可以随时获取出来
    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
        //1.将页面提交的密码进行MD5加密处理
        String password = employee.getPassword();
        password= DigestUtils.md5DigestAsHex(password.getBytes());

        //2.根据页面提交的用户名username查询数据库
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Employee::getUsername,employee.getUsername());
        Employee emp = employeeService.getOne(queryWrapper);  //使用getOne:因为user_name字段有unique唯一约束,不会出现查询出多个结果

        //3.如果没有查询到则返回登录失败结果
        if (emp == null){
            return R.error("登录失败");  //因为error为静态方法,所以可以在该类中直接调用
        }

        //4.密码比对,如果不一致则返回登录结果
        if (!emp.getPassword().equals(password)) {
            return R.error("登录失败");
        }

        //5.查看员工状态,如果已为禁用状态,则返回员工已禁用结果
        if (emp.getStatus() == 0){
            return R.error("账号已禁用");
        }

        //6.登录成功,将员工id存入session并返回登录成功结果
        request.getSession().setAttribute("employee",emp.getId());
        return R.success(emp);

    }

    /**
     * 员工退出
     * @param request
     * @return
     */
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        //清理session中保存的当前登录员工的id
        request.getSession().removeAttribute("employee");
        return R.success("退出成功");
    }
}

业务开发Day1-11-后台系统登录功能-代码开发(功能测试

测试

通过debug方式启动项目,在箭头指向位置添加断点
请添加图片描述
在浏览器上访问地址:http://localhost:8080/backend/page/login/login.html

  • 输入正确的用户名和密码点击登录
  • 在debug调试期间用时较长,前端在10s内得不到响应则会抛出异常,
  • 为了我们可以在后端进行长时间的调试,我们需要重新设置前端页面的响应超时时间找到request.js![image.png](https://img-blog.csdnimg.cn/img_convert/0cd7e202727da7ee0f88323def0934d3.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=172&id=u8819ada4&margin=[object Object]&name=image.png&originHeight=215&originWidth=316&originalType=binary&ratio=1&rotation=0&showTitle=false&size=8038&status=done&style=none&taskId=ua8ce46e5-8859-411b-aa49-9b118beefd0&title=&width=252.8)将timeout后面的数据多添加两个0,并且清除浏览器带有的缓存![image.png](https://img-blog.csdnimg.cn/img_convert/f4c25598381d8a666e10153c3c380e77.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=238&id=u6fd20002&margin=[object Object]&name=image.png&originHeight=297&originWidth=773&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34458&status=done&style=none&taskId=u52b86ece-6933-4d2d-bb6f-fff164f3f55&title=&width=618.4)
    清除浏览器缓存
    ![SV@BYHEVG%6DR4W240S~UIY.png](https://img-blog.csdnimg.cn/img_convert/dc046fb9945346d4c5d7073bb47471a9.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=drop&id=u51718e57&margin=[object Object]&name=SV@BYHEVG%6DR4W240S~UIY.png&originHeight=705&originWidth=1013&originalType=binary&ratio=1&rotation=0&showTitle=false&size=66624&status=done&style=none&taskId=u471c8823-bb4a-45ad-8d9f-2648adb222c&title=)

测试

  1. 输入错误的username,页面返回登录失败的信息
  2. 输入错误的密码,页面返回登录失败的信息
  3. 在数据库中将员工的status改为0,表示该员工处于被禁用状态,页面返回登录失败的信息

业务开发Day1-12-后台系统退出功能_需求分析&代码开发&功能测试

功能测试

![image.png](https://img-blog.csdnimg.cn/img_convert/5bcb77e20ad6b816cd6a474ac51b21d0.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=157&id=u60fc3c7c&margin=[object Object]&name=image.png&originHeight=196&originWidth=1302&originalType=binary&ratio=1&rotation=0&showTitle=false&size=145730&status=done&style=none&taskId=u0ac3f615-85e9-4994-936f-ce5e50b432b&title=&width=1041.6)

在EmployeeController类中添加logout方法

/**
     * 员工退出
     * @param request
     * @return
     */
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        //清理session中保存的当前登录员工的id
        request.getSession().removeAttribute("employee");
        return R.success("退出成功");
    }

登录成功时![image.png](https://img-blog.csdnimg.cn/img_convert/bdb78b8ecd3ac88295a2fbfc4ffc98fc.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=301&id=ua0352eca&margin=[object Object]&name=image.png&originHeight=376&originWidth=866&originalType=binary&ratio=1&rotation=0&showTitle=false&size=30772&status=done&style=none&taskId=u2c179efd-452c-4ae3-a2bb-2aa0ee6527e&title=&width=692.8)退出登录后![image.png](https://img-blog.csdnimg.cn/img_convert/50208dd3f38a4acd316af8901bda5ba7.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=225&id=udfe88845&margin=[object Object]&name=image.png&originHeight=281&originWidth=882&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21580&status=done&style=none&taskId=ufcae0e40-28d0-45b5-ac8d-41d2811b007&title=&width=705.6)

业务开发Day1-13-分析后台系统首页构成和效果展示方式

展示效果以及分析

![image.png](https://img-blog.csdnimg.cn/img_convert/721b82151606ea709a7fb3960dd5ac16.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=615&id=ub29cb91a&margin=[object Object]&name=image.png&originHeight=769&originWidth=242&originalType=binary&ratio=1&rotation=0&showTitle=false&size=20305&status=done&style=none&taskId=u308d4502-81f9-44d4-8107-6bf6cb5999b&title=&width=193.6)在index.html页面下的menuList作为数据的准备![image.png](https://img-blog.csdnimg.cn/img_convert/afe29de83bfa166b0a8141f77b61e07e.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=535&id=u183d1739&margin=[object Object]&name=image.png&originHeight=669&originWidth=712&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46793&status=done&style=none&taskId=uc268b659-0866-4534-812d-7c87b2b43dd&title=&width=569.6)

遍历menuList的代码块,里面各个标注对应的重要含义

  1. 遍历menuList
  2. v-if,根据提供的menuList可知并不满足条件
  3. 标签名:通过name属性定义
  4. 如果v-if不满足条件,则通过v-else
  5. 点击菜单,会执行menuHandle方法

![image.png](https://img-blog.csdnimg.cn/img_convert/75ff6085596f867ad879ab00703d1538.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=655&id=uc7167944&margin=[object Object]&name=image.png&originHeight=819&originWidth=888&originalType=binary&ratio=1&rotation=0&showTitle=false&size=107151&status=done&style=none&taskId=uc80c276b-4706-4928-a7a6-dcdd1c21770&title=&width=710.4)

menuHandle方法最重要的是红框的语句![image.png](https://img-blog.csdnimg.cn/img_convert/c7bf9980bcc543438aebb131e7f2470f.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=185&id=u24dc10ec&margin=[object Object]&name=image.png&originHeight=231&originWidth=449&originalType=binary&ratio=1&rotation=0&showTitle=false&size=20320&status=done&style=none&taskId=uaa1d707a-a7be-414b-b3af-5f457fbe7f5&title=&width=359.2)

定义了一个iframe,用于展示另一个页面,这个页面从哪来?传给我什么数据,我就展示什么数据![image.png](https://img-blog.csdnimg.cn/img_convert/5410588a9d61125db4622fef2494740b.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=222&id=u6b364002&margin=[object Object]&name=image.png&originHeight=278&originWidth=320&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21583&status=done&style=none&taskId=ueae42e57-4ec4-46aa-a93c-9bf02fe025e&title=&width=256)

那为什么登录成功后就是员工管理界面,因为在html中设置了初始值,当我们在点击菜单的时候,其实就是在切换url,展示一个新的界面
在html页面设置的初始界面![image.png](https://img-blog.csdnimg.cn/img_convert/ba19c92130d8712075f28f8e872fdae6.png#clientId=u16973528-691f-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=130&id=u6ce5613d&margin=[object Object]&name=image.png&originHeight=163&originWidth=413&originalType=binary&ratio=1&rotation=0&showTitle=false&size=12549&status=done&style=none&taskId=u9cba5344-5599-4e83-a9f1-660cd65c85c&title=&width=330.4)

举报

相关推荐

0 条评论