当前位置:网站首页>Ruiji takeout - day01
Ruiji takeout - day01
2022-07-28 12:01:00 【Passing coder】
Catalog
Development environment construction
Database environment construction
Static resource mapping configuration class
Background login function development
establish Controller、 Service、 Mapper、 Entity class 、R object
Sort out the login method and processing logic
Background system exit function
Overall introduction
Technology selection

Functional architecture

role

Development environment construction
Database environment construction

maven Project structures,
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zqf</groupId>
<artifactId>reggie_take_out</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</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>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<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>
<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.3.7.RELEASE</version>
</plugin>
</plugins>
</build>
</project>Import static resources

Static resource mapping configuration class
package com.zqf.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 {
/**
* Static resource mapping
* @param registry
*/
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info(" Start static resource mapping ");
// Resource processor , route
registry.addResourceHandler("/backed/**").addResourceLocations("classpath:/backend/");
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
}
}
Background login function development
Demand analysis
The background staff login corresponds to the following table :
Be careful :
The front end obtains these values from the returned results , This requires that the data processed by the server contain code,data,msg. It clarifies what kind of data the server should respond to after processing data .

Code development
establish Controller、 Service、 Mapper、 Entity class 、R object
- 1) Create entity class Employee, and employee Table to map
package com.zqf.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;
/**
* Employee entity
*/
@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;// Id card number
private Integer status;
private LocalDateTime createTime;
private LocalDateTime updateTime;
@TableField(fill = FieldFill.INSERT)
private Long createUser;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}
- 2) establish EmployeeMapper Interface
package com.zqf.reggie.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zqf.reggie.entity.Employee;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EmployeeMapper extends BaseMapper<Employee>{
}- 3) establish Service And implementation class
package com.zqf.reggie.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zqf.reggie.entity.Employee;
public interface EmployeeService extends IService<Employee> {
}package com.zqf.reggie.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zqf.reggie.entity.Employee;
import com.zqf.reggie.mapper.EmployeeMapper;
import com.zqf.reggie.service.EmployeeService;
import org.springframework.stereotype.Service;
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper,Employee> implements EmployeeService{
}
- Create presentation layer Controller
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
}- Import the general return result class R
This class is a general result class , All the results of the server response will eventually be packaged into this type and returned to the front-end page
package com.zqf.reggie.common;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* General return result , The data responded by the server will eventually be encapsulated into this object
* @param <T>
*/
@Data
public class R<T> {
private Integer code; // code :1 success ,0 And other numbers are failures
private String msg; // error message
private T data; // data
private Map map = new HashMap(); // Dynamic data
// When the response is successful , Return to one R object
public static <T> R<T> success(T object) {
R<T> r = new R<T>();
r.data = object;
r.code = 1;
return r;
}
// When the response fails , Return to one R object
public static <T> R<T> error(String msg) {
R r = new R();
r.msg = msg;
r.code = 0;
return r;
}
// Used for operation Map Dynamic data
public R<T> add(String key, Object value) {
this.map.put(key, value);
return this;
}
}
Sort out the login method and processing logic

- Login logic implementation
/**
* Employee login
* @param request
* @param employee
* @return
*/
@PostMapping("/login")
public R<Employee> login(HttpServletRequest request,@RequestBody Employee employee){
//1、 Submit the password of the page password Conduct md5 Encryption processing
String password = employee.getPassword();
password = DigestUtils.md5DigestAsHex(password.getBytes());
//2、 According to the user name submitted on the page username Query the database
LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Employee::getUsername,employee.getUsername());
Employee emp = employeeService.getOne(queryWrapper);
//3、 If there is no query, the login failure result will be returned
if(emp == null){
return R.error(" Login failed ");
}
//4、 Password comparison , If not, the login failure result will be returned
if(!emp.getPassword().equals(password)){
return R.error(" Login failed ");
}
//5、 View employee status , If it is disabled , The disabled employee result is returned
if(emp.getStatus() == 0){
return R.error(" Account has been disabled ");
}
//6、 Login successful , Staff id Deposit in Session And return the login success result
request.getSession().setAttribute("employee",emp.getId());
return R.success(emp);
}A functional test
( Landing successful , Jump to another page ) A little
Background system exit function
Demand analysis

Code implementation
/**
* Employee exit
* @param request
* @return
*/
@PostMapping("/logout")
public R<String> logout(HttpServletRequest request){
// clear Session Of the currently logged in employee saved in id
request.getSession().removeAttribute("employee");
return R.success(" Quit successfully ");
}边栏推荐
- Static proxy instance
- Final modifier attribute
- tolua之wrap文件的原理与使用
- js代码如何被浏览器引擎编译执行的?
- Lua middle__ index、__ Understanding of newindex, rawget and rawset
- What is WordPress
- 14、用户web层服务(二)
- [pyGame practice] the super interesting bubble game is coming - may you be childlike and always happy and simple~
- P5472 [NOI2019] 斗主地(期望、数学)
- Excel shortcut keys (letters + numbers) Encyclopedia
猜你喜欢

Lua对table进行深拷贝

移动端人脸风格化技术的应用

Saltstack command injection vulnerability analysis (cve-2020-16846)

PFP会是数字藏品的未来吗?

Autumn recruit offer harvesters, and take the offers of major manufacturers at will

强缓存、协商缓存具体过程

Upgrading of computing power under the coordination of software and hardware, redefining productivity

简单选择排序与堆排序

Hcip (configuration of GRE and mGRE and OSPF related knowledge)

Globalthis is not defined solution
随机推荐
Redis installation
15. User web layer services (III)
Today's sleep quality record 74 points
Business visualization - make your flowchart'run'(4. Actual business scenario test)
Reflect 机制获取Class 的属性和方法信息
How to effectively implement a rapid and reasonable safety evacuation system in hospitals
R language ggplot2 visualization: use the ggboxplot function of ggpubr package to visualize the box diagram and customize the fill parameter to configure the filling color of the box
Reasons and solutions for moving the first column to the last column in El table
[diary of supplementary questions] [2022 Niuke summer school 2] h-take the elevator
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
Several reincarnation stories
Solutions to slow start of MATLAB
Shell (I)
程序的存储态与运行态
Software testing and quality learning notes 1 --- black box testing
Let me think about Linear Algebra: a summary of basic learning of linear algebra
Stored state and running state of program
Skiasharp's WPF self drawn drag ball (case version)
How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I