first can version

This commit is contained in:
zeaslity
2022-11-21 18:26:41 +08:00
parent 64cf98cf7e
commit 80b66375a3
10 changed files with 22 additions and 10 deletions

View 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);
}
}

View 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);
}
}

View 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;
}
}

View File

@@ -0,0 +1 @@

View File

@@ -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() {
}
}