first can version
This commit is contained in:
13
common/src/main/java/io/wdd/wddcommon/CommonApplication.java
Normal file
13
common/src/main/java/io/wdd/wddcommon/CommonApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package io.wdd.wddcommon;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CommonApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CommonApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
49
common/src/main/java/io/wdd/wddcommon/utils/R.java
Normal file
49
common/src/main/java/io/wdd/wddcommon/utils/R.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package io.wdd.wddcommon.utils;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
33
common/src/main/java/io/wdd/wddcommon/utils/ResultStat.java
Normal file
33
common/src/main/java/io/wdd/wddcommon/utils/ResultStat.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package io.wdd.wddcommon.utils;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
1
common/src/main/resources/application.properties
Normal file
1
common/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.wdd.wddcommon;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class CommonApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user