forked from macrozheng/mall-swarm
-
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
1 parent
cdd332a
commit b580085
Showing
34 changed files
with
500 additions
and
634 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
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,39 @@ | ||
<?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> | ||
<groupId>com.macro.mall</groupId> | ||
<artifactId>mall-common</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>mall-common</name> | ||
<description>mall-common project for mall</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.pagehelper</groupId> | ||
<artifactId>pagehelper</artifactId> | ||
<version>5.1.8</version> | ||
</dependency> | ||
<!--Swagger-UI API文档生产工具--> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
<version>2.7.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger-ui</artifactId> | ||
<version>2.7.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
<version>2.1.5.RELEASE</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</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
118 changes: 118 additions & 0 deletions
118
mall-common/src/main/java/com/macro/mall/common/api/CommonResult.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,118 @@ | ||
package com.macro.mall.common.api; | ||
|
||
/** | ||
* 通用返回对象 | ||
*/ | ||
public class CommonResult<T> { | ||
private long code; | ||
private String message; | ||
private T data; | ||
|
||
/** | ||
* 普通成功返回 | ||
* | ||
* @param data 获取的数据 | ||
*/ | ||
public static <T> CommonResult<T> success(T data) { | ||
CommonResult<T> result = new CommonResult<T>(); | ||
result.setCode(ResultCode.SUCCESS.getCode()); | ||
result.setMessage(ResultCode.SUCCESS.getMsg()); | ||
result.setData(data); | ||
return result; | ||
} | ||
|
||
/** | ||
* 普通成功返回 | ||
* | ||
* @param data 获取的数据 | ||
*/ | ||
public static <T> CommonResult<T> success(T data,String message) { | ||
CommonResult<T> result = new CommonResult<T>(); | ||
result.setCode(ResultCode.SUCCESS.getCode()); | ||
result.setMessage(message); | ||
result.setData(data); | ||
return result; | ||
} | ||
|
||
/** | ||
* 通过错误码对象构造返回结果 | ||
*/ | ||
public static <T> CommonResult<T> failed(IErrorCode errorCode) { | ||
CommonResult<T> result = new CommonResult<T>(); | ||
result.setCode(errorCode.getCode()); | ||
result.setMessage(errorCode.getMsg()); | ||
return result; | ||
} | ||
|
||
/** | ||
* 普通失败提示信息 | ||
*/ | ||
public static <T> CommonResult<T> failed(String message) { | ||
CommonResult<T> result = new CommonResult<T>(); | ||
result.setCode(ResultCode.FAILED.getCode()); | ||
result.setMessage(message); | ||
return result; | ||
} | ||
|
||
/** | ||
* 普通操作失败 | ||
*/ | ||
public static <T> CommonResult<T> failed() { | ||
return failed(ResultCode.FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败使用 | ||
*/ | ||
public static <T> CommonResult<T> validateFailed() { | ||
return failed(ResultCode.VALIDATE_FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败使用 | ||
*/ | ||
public static <T> CommonResult<T> validateFailed(String message) { | ||
CommonResult<T> result = new CommonResult<T>(); | ||
result.setCode(ResultCode.FAILED.getCode()); | ||
result.setMessage(message); | ||
return result; | ||
} | ||
|
||
/** | ||
* 用户没有登录 | ||
*/ | ||
public static <T> CommonResult<T> unauthorized() { | ||
return failed(ResultCode.UNAUTHORIZED); | ||
} | ||
|
||
/** | ||
* 用户没有相应权限 | ||
*/ | ||
public static <T> CommonResult<T> forbidden() { | ||
return failed(ResultCode.UNAUTHORIZED); | ||
} | ||
|
||
public long getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(long code) { | ||
this.code = code; | ||
} | ||
|
||
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
mall-common/src/main/java/com/macro/mall/common/api/IErrorCode.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,11 @@ | ||
package com.macro.mall.common.api; | ||
|
||
/** | ||
* 封装API的错误码 | ||
* Created by macro on 2019/4/19. | ||
*/ | ||
public interface IErrorCode { | ||
long getCode(); | ||
|
||
String getMsg(); | ||
} |
28 changes: 28 additions & 0 deletions
28
mall-common/src/main/java/com/macro/mall/common/api/ResultCode.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 com.macro.mall.common.api; | ||
|
||
/** | ||
* 枚举了一些常用API操作码 | ||
* Created by macro on 2019/4/19. | ||
*/ | ||
public enum ResultCode implements IErrorCode { | ||
SUCCESS(200, "操作成功"), | ||
FAILED(500, "操作失败"), | ||
VALIDATE_FAILED(404, "参数检验失败"), | ||
UNAUTHORIZED(401, "暂未登录或token已经过期"), | ||
FORBIDDEN(403, "没有相关权限"); | ||
private long code; | ||
private String msg; | ||
|
||
private ResultCode(long code, String msg) { | ||
this.code = code; | ||
this.msg = msg; | ||
} | ||
|
||
public long getCode() { | ||
return code; | ||
} | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
} |
Oops, something went wrong.