And a truncated part of the code using the techniques selected from

pom file

<?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.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.repairsystem</groupId>
<artifactId>repairsys</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>repairsys</name>
<description>this is electronic equipment repair system</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.5.7.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</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-mail</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.12.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.12.RELEASE</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

<!-- springboot分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>

</project>


High multiplexing response class:

package com.repairsystem.repairsys.common;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;

/ **
* highly multiplexed service response object
* @param <T>
* /
@JsonSerialize (= the include JsonSerialize.Inclusion.NON_NULL) // json serialization time, if a null object, key will disappear
public class ServerResponse <T> {
Private int Status;
Private String MSG;
Private Data T;

private ServerResponse(int status){
this.status = status;
}
private ServerResponse(int status, String msg){
this.status = status;
this.msg = msg;
}
private ServerResponse(int status, String msg, T data){
this.status = status;
this.msg = msg;
this.data = data;
}
private ServerResponse(int status, T data){
this.status = status;
this.data = data;
}
@JsonIgnore //使之不在json序列化的结果当中
public boolean isSuccess(){
return this.status == ResponseCode.SUCCESS.getCode();
}

public int getStatus() {
return status;
}

public String getMsg() {
return msg;
}

public T getData() {
return data;
}

public static <T> ServerResponse<T> createBySuccess(){
return new ServerResponse(ResponseCode.SUCCESS.getCode());
}
public static <T> ServerResponse<T> createBySuccessMassage(String msg){
return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg);
}
public static <T> ServerResponse<T> createBySuccess(T data){
return new ServerResponse(ResponseCode.SUCCESS.getCode(),data);
}
public static <T> ServerResponse<T> createBySuccess(String msg,T data){
return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg,data);
}
public static <T> ServerResponse<T> createByError(){
return new ServerResponse<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
}
public static <T> ServerResponse<T> createByErrorMassage(String errorMassage){
return new ServerResponse<T>(ResponseCode.ERROR.getCode(),errorMassage);
}
public static <T> ServerResponse<T> createByErrorCodeMassage(int errorCode,String errorMassage) {
return new ServerResponse<T>(errorCode, errorMassage);
}
}


Its role is to json format data into a desired sequence as a generic class T, such a method of providing a record of such objects, as the server's response.

Such as:

"status": 0,
"msg": "登录成功!",
"data":{
"adminId": 1,
"adminNum": "978978",
"adminPassword": "",
"adminName": "zplw",
"adminTel": "12345678900",
"adminImg": "css/img/content/p3.jpg"
},
"success": true

 


"Status": 0,
"msg": "login is successful!",
"the Data": {
"userId": 1,
"userNum": "978.24 thousand",
"the userPassword": "",
"userName": "ZZZZ",
"userBirth": "1998-03-02 in",
"userTel": "91,938,989,189",
"userImg": null
},
"Success": to true

use of technology:
the server: springboot + mybatis + websocket
front end: html + css + bootstrap JQ + ajax +
---------------------
author: Zou sketch
source: CSDN
original: https: //blog.csdn.net/weixin_40675950/article/details/ 90678102
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/kangrui201610411307/p/10965685.html