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>
<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>
高复用响应类:
package com.repairsystem.repairsys.common;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
*高复用服务响应对象
* @param <T>
*/
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) //序列化json的时候,如果是null的对象,key也会消失
public class ServerResponse<T> {
private int status;
private String msg;
private T data;
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);
}
}
其作用是将所需序列化为json格式的数据作为此类的泛型T,用此类提供的方法创出此类对象,作为服务器的响应信息。
如:
"status": 0,
"msg": "登录成功!",
"data":{
"adminId": 1,
"adminNum": "978978",
"adminPassword": "",
"adminName": "zplw",
"adminTel": "12345678900",
"adminImg": "css/img/content/p3.jpg"
},
"success": true
"status": 0,
"msg": "登录成功!",
"data":{
"userId": 1,
"userNum": "978240",
"userPassword": "",
"userName": "zzzz",
"userBirth": "1998-03-02",
"userTel": "91938989189",
"userImg": null
},
"success": true
运用技术:
服务器端:springboot+mybatis+websocket
前端:html+css+bootstrap+jq+ajax
---------------------
作者:邹小品
来源:CSDN
原文:https://blog.csdn.net/weixin_40675950/article/details/90678102
版权声明:本文为博主原创文章,转载请附上博文链接!