首页 > 其他分享 >瑞吉外卖01

瑞吉外卖01

时间:2022-10-04 23:02:07浏览次数:41  
标签:01 boot private 瑞吉 springframework 外卖 org import com

1.创建数据库(导入sql文件)

2.创建springboot项目,完成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.7.4</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.example</groupId>
12     <artifactId>reggie</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>reggie</name>
15     <description>reggie</description>
16     <properties>
17         <java.version>11</java.version>
18     </properties>
19     <dependencies>
20         <dependency>
21             <groupId>org.mybatis.spring.boot</groupId>
22             <artifactId>mybatis-spring-boot-starter</artifactId>
23             <version>2.2.2</version>
24         </dependency>
25 
26 
27         <dependency>
28             <groupId>org.projectlombok</groupId>
29             <artifactId>lombok</artifactId>
30             <optional>true</optional>
31         </dependency>
32         <dependency>
33             <groupId>org.springframework.boot</groupId>
34             <artifactId>spring-boot-starter-test</artifactId>
35             <scope>test</scope>
36         </dependency>
37         <dependency>
38             <groupId>com.baomidou</groupId>
39             <artifactId>mybatis-plus-boot-starter</artifactId>
40             <version>3.4.2</version>
41         </dependency>
42         <dependency>
43             <groupId>com.alibaba</groupId>
44             <artifactId>fastjson</artifactId>
45             <version>1.2.76</version>
46         </dependency>
47         <dependency>
48             <groupId>org.springframework.boot</groupId>
49             <artifactId>spring-boot-starter-web</artifactId>
50         </dependency>
51 
52         <dependency>
53             <groupId>commons-lang</groupId>
54             <artifactId>commons-lang</artifactId>
55             <version>2.6</version>
56         </dependency>
57 
58         <dependency>
59             <groupId>mysql</groupId>
60             <artifactId>mysql-connector-java</artifactId>
61             <scope>runtime</scope>
62         </dependency>
63 
64         <dependency>
65             <groupId>com.alibaba</groupId>
66             <artifactId>druid-spring-boot-starter</artifactId>
67             <version>1.1.23</version>
68         </dependency>
69         <dependency>
70             <groupId>org.springframework</groupId>
71             <artifactId>spring-webmvc</artifactId>
72             <version>5.3.20</version>
73         </dependency>
74     </dependencies>
75 
76     <build>
77         <plugins>
78             <plugin>
79                 <groupId>org.springframework.boot</groupId>
80                 <artifactId>spring-boot-maven-plugin</artifactId>
81                 <configuration>
82                     <excludes>
83                         <exclude>
84                             <groupId>org.projectlombok</groupId>
85                             <artifactId>lombok</artifactId>
86                         </exclude>
87                     </excludes>
88                 </configuration>
89             </plugin>
90         </plugins>
91     </build>
92 
93 </project>

3.完成yml文件配置

 1 server:
 2   port: 8080
 3 spring:
 4   application:
 5     name: reggie_take_out
 6   datasource:
 7     druid:
 8       driver-class-name: com.mysql.cj.jdbc.Driver
 9       url: jdbc:mysql://localhost:3306/reggie?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
10       username: root
11       password: 123456
12 mybatis-plus:
13   configuration:
14     #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
15     map-underscore-to-camel-case: true
16     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
17   global-config:
18     db-config:
19       id-type: ASSIGN_ID

 

4.完成前端资源导入

 

 

 5.创建config包,并创建WebMvcConfig类(放行静态资源)

 1 @Slf4j
 2 @Configuration
 3 public class WebMvcConfig extends WebMvcConfigurationSupport {
 4     /**
 5      * 放行静态资源
 6      */
 7     @Override
 8     protected void addResourceHandlers(ResourceHandlerRegistry registry) {
 9         log.info("成功!");
10         registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
11         registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
12     }
13 }

6.创建entity包导入员工类

 1 /**
 2  * 员工实体类
 3  */
 4 @Data
 5 public class Employee implements Serializable {
 6 
 7     private static final long serialVersionUID = 1L;
 8 
 9     private Long id;
10 
11     private String username;
12 
13     private String name;
14 
15     private String password;
16 
17     private String phone;
18 
19     private String sex;
20 
21     private String idNumber;//身份证号码  驼峰命名(对应id_number)
22 
23     private Integer status;
24 
25     private LocalDateTime createTime;
26 
27     private LocalDateTime updateTime;
28 
29     @TableField(fill = FieldFill.INSERT)
30     private Long createUser;
31 
32     @TableField(fill = FieldFill.INSERT_UPDATE)
33     private Long updateUser;
34 
35 }

7.创建mapper包并创建Employeemapper接口

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

8.创建service包,和iml包

 

 

 9.创建EmpoleeService接口

 

 

 10.EmployeeService接口实现类

1 @Service
2 public class EmployeeServiceIml extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
3 }

11.创建controller包并创建EmployeeController类(实现登录和退出)

 1 package com.example.reggie.controller;
 2 
 3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 5 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 6 import com.example.reggie.common.R;
 7 import com.example.reggie.entity.Employee;
 8 import com.example.reggie.service.EmployeeService;
 9 import lombok.extern.slf4j.Slf4j;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.util.DigestUtils;
12 import org.springframework.web.bind.annotation.PostMapping;
13 import org.springframework.web.bind.annotation.RequestBody;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RestController;
16 
17 import javax.servlet.http.HttpServletRequest;
18 
19 /**
20  * 员工登录
21 
22  */
23 @Slf4j
24 @RestController
25 @RequestMapping("/employee")
26 public class EmployeeController {
27     @Autowired
28     private EmployeeService employeeService;
29     @PostMapping("/login")
30     public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee) {//@RequestBody的作用其实是将json格式的数据转为java对象
31         //1.将页面提交的密码进行md5加密
32         String password = employee.getPassword();
33         password=DigestUtils.md5DigestAsHex(password.getBytes());
34         //2.将页面提交的username进行数据库查询
35         LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
36         queryWrapper.eq(Employee::getUsername, employee.getUsername());//queryWrapper.eq(实体类::属性,值);
37         Employee emp = employeeService.getOne(queryWrapper);
38 
39         //3.如果没有查询到将返回查询失败结果
40         if(emp==null){
41             return  R.error("登录失败!");
42         }
43 
44         //4.密码比对,如果不一致将返回登陆失败结果
45         if(!emp.getPassword().equals(password)){
46             return  R.error("登录失败!");
47         }
48 
49         //5.查询员工状态,如果为已禁用状态,将返回员工已禁用结果
50         if (emp.getStatus()==0){
51 
52             return R.error("账号已禁用");
53         }
54         //6.登陆成功,将员工id存入session并返回登陆成功结果
55         request.getSession().setAttribute("employee",emp.getId());
56         return R.success(emp);
57 
58 
59     }
60     /**
61      * 员工退出
62      * @param request
63      * @return
64      */
65     @PostMapping("/logout")
66     public R<String> logout(HttpServletRequest request){
67         //清理Session中保存的当前登录员工的id
68         request.getSession().removeAttribute("employee");
69         return R.success("退出成功");
70     }
71 
72 }

 




标签:01,boot,private,瑞吉,springframework,外卖,org,import,com
From: https://www.cnblogs.com/zhaosanmao/p/16754739.html

相关文章

  • 01-业界主流的分布式消息队列与MQ的技术选型
    业界主流的分布式消息队列(MQ)与技术选型MQ的应用场景服务解耦削峰填谷异步化缓冲MQ的应用思考点业务生产端的可靠性投递消费端的幂等性MQMQ高可用......
  • 01-单节点文件上传存在的问题
    目前文件上传的问题单向存储不支持集群文件数据冗余(高可用概念)可扩展差因为单向存储文件,会被Nginx轮询,导致上传到一台Tomcat上,会导致后续如果该请求没有......
  • 01.JavaScript简介
    JavaScript(JS)isalightweight,interpreted,orjust-in-timecompiledprogramminglanguagewithfirst-classfunctions.Whileitismostwell-knownasthe......
  • 做题记录整理图论1 P3629 [APIO2010] 巡逻(2022/10/3)
    P3629[APIO2010]巡逻写一道题顶写三道题系列,为了写这道题专门去学习了树的直径的两种求法,可以说是血赚了https://www.luogu.com.cn/blog/lscsznmhw/solution-p3629......
  • Microsoft word 2019 for Mac中文激活版
    Microsoftword2019是功能强大的文档编辑工具,被认为是office的主要程序,拥有文字搜索、导航、文档的编辑共享、重点部分的标注等多种功能,word拥有视图学些功能,字体的颜色变......
  • 贤鱼的刷题日常--P1981 [NOIP2013 普及组] 表达式求值
    ......
  • 07_音频录制01_命令行
    终于要开始进行FFmpeg实战了,一起来感受一下FFmpeg的强大吧。命令简介FFmpeg的bin目录中提供了3个命令(可执行程序),可以直接在命令行上使用。ffmpegffmpeg的主要作用:对......
  • 013——static静态关键字
    1.static静态关键字1.1static是什么,static修饰成员变量的用法1.1.1static是什么?static是静态的意思,可以用来修饰成员变量、成员方法。static修饰成员变量之后称为......
  • 01_Mac安装Homebrew
    目录1官方1.1前提1.2安装2其他安装方法2.1安装homebrew-core2.2安装homebrew-cask3源3.1查看源3.2设置源3.3设置bottles镜像3.4重置为官方源4卸载1官方Home......
  • Luogu P5089 [eJOI2018] 元素周期表 题解
    (从洛谷博客搬过来的)这道题嘛..主要还是找性质推规律。拿到题,第一眼:噢噢爆搜啊。第二眼:噢噢贪心啊。第三眼:很好贪心假了。然后苦思冥想半个小时去看题解。看到兔队的......