-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 09f0a6f
Showing
27 changed files
with
1,699 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
dist |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionUrl=https://maven.aliyun.com/repository/public/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip | ||
wrapperUrl=https://maven.aliyun.com/repository/public/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>fun-code</artifactId> | ||
<groupId>work.lichong</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>demo</artifactId> | ||
|
||
<properties> | ||
<web.dir>${project.parent.basedir}/demo-web</web.dir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>demo</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<configuration> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
<outputDirectory>${project.build.directory}/classes</outputDirectory> | ||
<resources> | ||
<resource> | ||
<targetPath>${basedir}/target/classes/static</targetPath> | ||
<directory>${web.dir}/dist</directory> | ||
</resource> | ||
<resource> | ||
<targetPath>${basedir}/target/classes</targetPath> | ||
<directory>${basedir}/src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package work.lichong.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@SpringBootApplication | ||
@EnableWebMvc | ||
public class DemoApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DemoApplication.class, args); | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
demo/src/main/java/work/lichong/demo/common/bean/ApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2022. 李冲. All rights reserved. | ||
*/ | ||
|
||
package work.lichong.demo.common.bean; | ||
|
||
import work.lichong.demo.common.enumeration.ResponseStatus; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
/** | ||
* 统一返回结果 | ||
* | ||
* @author 李冲 | ||
* @see <a href="https://lichong.work">李冲博客</a> | ||
* @since 0.0.1 | ||
*/ | ||
@ApiModel(value = "统一返回结果") | ||
public class ApiResponse<T> { | ||
|
||
@ApiModelProperty(value = "状态码") | ||
private Integer status; | ||
|
||
@ApiModelProperty(value = "响应信息") | ||
private String message; | ||
|
||
@ApiModelProperty(value = "响应体数据") | ||
private T data; | ||
/** | ||
* 是否压缩数据 gzip | ||
*/ | ||
@ApiModelProperty(value = "是否gzip压缩数据") | ||
private boolean compressData; | ||
|
||
public ApiResponse(String message) { | ||
this.message = message; | ||
} | ||
|
||
public ApiResponse(Integer status, String message, T data) { | ||
this.status = status; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
|
||
public ApiResponse(Integer code, String message) { | ||
this(code, message, null); | ||
} | ||
|
||
public ApiResponse(ResponseStatus status, String message) { | ||
this(status.getStatus(), message, null); | ||
} | ||
|
||
public ApiResponse(Integer status, T data) { | ||
this(ResponseStatus.getRequestStatus(status), data); | ||
} | ||
|
||
public ApiResponse(ResponseStatus status, T data) { | ||
this(status.getStatus(), status.getMessage(), data); | ||
} | ||
|
||
public ApiResponse(ResponseStatus status) { | ||
this(status.getStatus(), status.getMessage(), null); | ||
} | ||
|
||
public boolean isCompressData() { | ||
return compressData; | ||
} | ||
|
||
public void setCompressData(boolean compressData) { | ||
this.compressData = compressData; | ||
} | ||
|
||
public Integer getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(Integer status) { | ||
this.status = status; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public void setData(T data) { | ||
this.data = data; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
demo/src/main/java/work/lichong/demo/common/bean/ApiResponseWithCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package work.lichong.demo.common.bean; | ||
|
||
import work.lichong.demo.common.enumeration.ResponseStatus; | ||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* 统一返回结果 | ||
* | ||
* @author 李冲 | ||
* @see <a href="https://lichong.work">李冲博客</a> | ||
* @since 0.0.1 | ||
*/ | ||
@ApiModel(value = "带数量的统一返回结果", parent = ApiResponse.class) | ||
public class ApiResponseWithCount<T> extends ApiResponse<T> { | ||
|
||
@Getter | ||
@Setter | ||
@ApiModelProperty(value = "数量") | ||
private long count; | ||
|
||
public ApiResponseWithCount(ResponseStatus status, T data) { | ||
super(status.getStatus(), status.getMessage(), data); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
demo/src/main/java/work/lichong/demo/common/enumeration/ResponseStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package work.lichong.demo.common.enumeration; | ||
|
||
/** | ||
* http api 状态码 | ||
* | ||
* @author 李冲 | ||
* @see <a href="https://lichong.work">李冲博客</a> | ||
* @since 0.0.1 | ||
*/ | ||
public enum ResponseStatus { | ||
|
||
// [GET]:服务器成功返回用户请求的数据 | ||
RESPONSE_2XX_OK(200, "Ok"), | ||
// [POST/PUT/PATCH]:用户新建或修改数据成功。 | ||
RESPONSE_2XX_CREATE(201, "Created"), | ||
RESPONSE_2XX_UPDATED(201, "Updated"), | ||
// 表示一个请求已经进入后台排队(异步任务) | ||
RESPONSE_2XX_ACCEPTED(202, "Accepted"), | ||
// [DELETE]:用户删除数据成功。 | ||
RESPONSE_2XX_NO_CONTENT(204, "No Content"), | ||
|
||
// [GET/POST/PUT/PATCH]:语义有误,当前请求无法被服务器理解 | ||
RESPONSE_4XX_INVALID_REQUEST(400, "Invalid Request"), | ||
// 表示用户没有权限(令牌、用户名、密码错误) | ||
RESPONSE_4XX_UNAUTHORIZED(401, "Unauthorized"), | ||
// 表示用户得到授权(与401错误相对),但是访问是被禁止的 | ||
RESPONSE_4XX_FORBIDDEN(403, "Forbidden"), | ||
// 用户发出的请求针对的是不存在的记录,服务器没有进行操作等的。 | ||
RESPONSE_4XX_NOT_FOUND(404, "Not Found"), | ||
// 请求格式正确,但是由于含有语义错误,无法响应 | ||
RESPONSE_4XX_UNPROCESSABLE_ENTITY(422, "Unprocessable Entity"), | ||
// 重复校验未通过 | ||
RESPONSE_409_REPEAT(409, "重复校验未通过, 不能执行操作!"), | ||
|
||
// 服务器发生错误,用户将无法判断发出的请求是否成功。 | ||
RESPONSE_5XX_INTERNAL_SERVER_ERROR(500, "Internal Server Error"), | ||
// 服务器不支持实现请求所需要的功能 | ||
RESPONSE_5XX_NOT_IMPLEMENTED(501, "该接口已废弃,请参照文档及时更换"); | ||
|
||
private final int status; | ||
|
||
private final String message; | ||
|
||
ResponseStatus(int status, String message) { | ||
this.status = status; | ||
this.message = message; | ||
} | ||
|
||
public static ResponseStatus getRequestStatus(int status) { | ||
for (ResponseStatus msgPlatformStatus : values()) { | ||
if (msgPlatformStatus.status == status) { | ||
return msgPlatformStatus; | ||
} | ||
} | ||
throw new IllegalArgumentException("No matching constant for [" + status + "]"); | ||
} | ||
|
||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
Oops, something went wrong.