Skip to content

Commit

Permalink
修改响应类
Browse files Browse the repository at this point in the history
  • Loading branch information
叶云轩.MacBookPro committed Dec 15, 2019
1 parent 8257130 commit ddabbc8
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 101 deletions.
70 changes: 40 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,10 @@

<groupId>org.yyx.xf</groupId>
<artifactId>xf-util</artifactId>
<version>1.0.10-RELEASE</version>
<version>1.0.11-RELEASE</version>
<name>xf-util</name>
<description>xf的util单独包</description>
<!--region Maven私服-->
<!-- <repositories>-->
<!-- <repository>-->
<!-- <id>LenovoImageNexus</id>-->
<!-- <name>Lenovo-Image</name>-->
<!-- <url>http://124.202.140.137:9993/repository/lenovoimage-release/</url>-->
<!-- <releases>-->
<!-- <enabled>true</enabled>-->
<!-- </releases>-->
<!-- <snapshots>-->
<!-- <enabled>true</enabled>-->
<!-- </snapshots>-->
<!-- </repository>-->
<!-- </repositories>-->
<!-- region 用于jar发布的配置 -->
<!-- <distributionManagement>-->
<!-- <snapshotRepository>-->
<!-- <id>lenovoimage-snapshot</id>-->
<!-- <name>LenovoImage Nexus Snapshot</name>-->
<!-- <url>http://124.202.140.137:9993/repository/lenovoimage-snapshot/</url>-->
<!-- </snapshotRepository>-->
<!-- <repository>-->
<!-- <id>lenovoimage-release</id>-->
<!-- <name>LenovoImage Nexus Release</name>-->
<!-- <url>http://124.202.140.137:9993/repository/lenovoimage-release/</url>-->
<!-- </repository>-->
<!-- </distributionManagement>-->
<!-- endregion -->
<!--endregion-->

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<poi>3.17</poi>
Expand All @@ -56,6 +28,43 @@
<junit>4.12</junit>
<lombok>1.16.20</lombok>
</properties>

<repositories>
<repository>
<id>cjwy</id>
<name>cjwy</name>
<url>http://maven.frps.vanrentong.com/repository/cjwy-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<developers>
<developer>
<id>yyx</id>
<email>[email protected]</email>
<name>yyx</name>
<url>http://www.happyqing.com</url>
</developer>
</developers>

<distributionManagement>
<repository>
<id>release</id>
<name>cjwy-releases</name>
<url>http://maven.frps.vanrentong.com/repository/cjwy-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>cjwy-snapshots</name>
<url>http://maven.frps.vanrentong.com/repository/cjwy-snapshots/</url>
</snapshotRepository>
</distributionManagement>

<build>
<plugins>
<plugin>
Expand All @@ -79,6 +88,7 @@
</resource>
</resources>
</build>

<dependencies>
<!-- region spring boot starter web -->
<dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.yyx.xf.tool.web.domain.constant;

import lombok.Getter;

/**
* 响应常量
* <p>
*
* @author 叶云轩 at [email protected]
* @date 2018/10/14-21:45
*/
public enum ResponseEnum {

/**
* 请求成功时的响应码
*/
success("000000000", "请求成功", "request success"),
/**
* 请求失败时的响应码
*/
error("999999999", "服务器错误", "request failed");
/**
* 响应码
*/
@Getter
private String code;
/**
* 响应信息
*/
@Getter
private String msg;
/**
* 响应信息
*/
@Getter
private String des;

/**
* 枚举类构造
*
* @param code 响应码
* @param msg 响应信息
* @param des 响应信息
*/
ResponseEnum(String code, String msg, String des) {
this.code = code;
this.msg = msg;
this.des = des;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public interface BaseResponse<T> {
*
* @return 响应码
*/
Long getCode();
String getCode();

/**
* 设置响应码
*
* @param code 响应码
*/
void setCode(Long code);
void setCode(String code);

/**
* 获取返回的数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ResponseEntity<T> implements BaseResponse<T> {
/**
* 响应码
*/
private Long code;
private String code;
/**
* 响应码的说明
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ public class ResponseEntity<T> implements BaseResponse<T> {
* @param code 响应码
* @param msg 响应说明
*/
public ResponseEntity(Long code, String msg) {
public ResponseEntity(String code, String msg) {
this.code = code;
this.msg = msg;
}
Expand All @@ -60,7 +60,7 @@ public ResponseEntity() {
* @param msg 响应说明
* @param description 响应英文说明
*/
public ResponseEntity(Long code, String msg, String description) {
public ResponseEntity(String code, String msg, String description) {
this.code = code;
this.msg = msg;
this.description = description;
Expand Down
45 changes: 30 additions & 15 deletions src/main/java/org/yyx/xf/tool/web/util/UtilResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.yyx.xf.tool.web.util;

import org.yyx.xf.tool.web.domain.constant.ResponseConstant;
import org.yyx.xf.tool.web.domain.constant.ResponseEnum;
import org.yyx.xf.tool.web.domain.entity.BaseResponse;
import org.yyx.xf.tool.web.domain.entity.ResponseEntity;

Expand All @@ -25,7 +25,7 @@ private UtilResponse() {
* @return 封装的数据结构
*/
public static <T> ResponseEntity<T> error() {
return error(ResponseConstant.ERROR_CODE, ResponseConstant.ERROR, ResponseConstant.ERROR_DESC);
return generateErrorEntity();
}

/**
Expand All @@ -37,7 +37,7 @@ public static <T> ResponseEntity<T> error() {
* @param description 响应信息英文说明
* @return 封装的数据结构
*/
public static <T> ResponseEntity<T> error(Long code, String message, String description) {
public static <T> ResponseEntity<T> error(String code, String message, String description) {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(code);
responseEntity.setDescription(description);
Expand All @@ -47,16 +47,15 @@ public static <T> ResponseEntity<T> error(Long code, String message, String desc

/**
* 服务器异常
* 失败时不予前台返回数据.
*
* @param <T> 泛型
* @param baseResponse 响应结构
* @return 封装的数据结构
*/
@Deprecated
public static <T> ResponseEntity<T> error(BaseResponse<T> baseResponse) {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(baseResponse.getCode());
responseEntity.setDescription(baseResponse.getDescription());
responseEntity.setMsg(baseResponse.getMsg());
ResponseEntity<T> responseEntity = generateErrorEntity();
responseEntity.setTotal(baseResponse.getTotal());
responseEntity.setRows(baseResponse.getRows());
responseEntity.setData(baseResponse.getData());
Expand All @@ -72,10 +71,7 @@ public static <T> ResponseEntity<T> error(BaseResponse<T> baseResponse) {
* @return 封装的数据结构
*/
public static <T> ResponseEntity<T> success(T responseData, Long total) {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(ResponseConstant.SUCCESS_CODE);
responseEntity.setDescription(ResponseConstant.SUCCESS_DESC);
responseEntity.setMsg(ResponseConstant.SUCCESS);
ResponseEntity<T> responseEntity = generateSuccessEntity();
responseEntity.setTotal(total);
responseEntity.setRows(responseData);
return responseEntity;
Expand All @@ -98,12 +94,31 @@ public static <T> ResponseEntity<T> success() {
* @return 封装的数据结构
*/
public static <T> ResponseEntity<T> success(T responseData) {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(ResponseConstant.SUCCESS_CODE);
responseEntity.setDescription(ResponseConstant.SUCCESS_DESC);
responseEntity.setMsg(ResponseConstant.SUCCESS);
ResponseEntity<T> responseEntity = generateSuccessEntity();
responseEntity.setData(responseData);
return responseEntity;
}

/**
* 私有方法,生成成功响应
*/
private static <T> ResponseEntity<T> generateSuccessEntity() {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(ResponseEnum.success.getCode());
responseEntity.setDescription(ResponseEnum.success.getDes());
responseEntity.setMsg(ResponseEnum.success.getMsg());
return responseEntity;
}

/**
* 私有方法,生成失败响应
*/
private static <T> ResponseEntity<T> generateErrorEntity() {
ResponseEntity<T> responseEntity = new ResponseEntity<>();
responseEntity.setCode(ResponseEnum.error.getCode());
responseEntity.setDescription(ResponseEnum.error.getDes());
responseEntity.setMsg(ResponseEnum.error.getMsg());
return responseEntity;
}

}

0 comments on commit ddabbc8

Please sign in to comment.