add new common module

This commit is contained in:
zeaslity
2022-11-21 16:55:09 +08:00
parent 4ad15577f4
commit a6402a5f61
8 changed files with 16 additions and 8 deletions

View File

@@ -25,6 +25,14 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -0,0 +1,49 @@
package io.wdd.common;
import lombok.Data;
@Data
public class R<T> {
int code;
String msg;
T data;
private R(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public R() {
}
public static <T> R<T> ok(T data) {
return resetResult(data, ResultStat.SUCCESS);
}
public static <T> R<T> okNoData() {
return new R();
}
public static <T> R<T> failed(T data) {
return resetResult(data, ResultStat.FAILED);
}
// access from inner
private static <T> R<T> resetResult(T data, ResultStat resultStat) {
return new R(resultStat.getCode(), resultStat.getDescription(), data);
}
// access to public
public static <T> R<T> resetResult(int code, String msg, T data) {
return new R<>(code
, msg, data);
}
}

View File

@@ -0,0 +1,33 @@
package io.wdd.common;
public enum ResultStat {
SUCCESS(1000, "success"),
FAILED(5001, "failed"),
VALIDATE_FAILED(1002, "参数校验失败"),
PARAM_ERROR(1003, "请求参数错误!"),
BAD(5001, "all error !");
int code;
String description;
ResultStat(int code, String description){
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription(){
return description;
}
}