parent
3756c9f91a
commit
51e4a56177
@ -0,0 +1,17 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="CompilerConfiguration"> |
||||
<annotationProcessing> |
||||
<profile default="true" name="Default" enabled="true" /> |
||||
<profile name="Maven default annotation processors profile" enabled="true"> |
||||
<sourceOutputDir name="target/generated-sources/annotations" /> |
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> |
||||
<outputRelativeToContentRoot value="true" /> |
||||
<module name="vegetables" /> |
||||
</profile> |
||||
</annotationProcessing> |
||||
<bytecodeTargetLevel> |
||||
<module name="vegetables" target="8" /> |
||||
</bytecodeTargetLevel> |
||||
</component> |
||||
</project> |
@ -0,0 +1,20 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="RemoteRepositoriesConfiguration"> |
||||
<remote-repository> |
||||
<option name="id" value="central" /> |
||||
<option name="name" value="Central Repository" /> |
||||
<option name="url" value="https://repo.maven.apache.org/maven2" /> |
||||
</remote-repository> |
||||
<remote-repository> |
||||
<option name="id" value="central" /> |
||||
<option name="name" value="Maven Central repository" /> |
||||
<option name="url" value="https://repo1.maven.org/maven2" /> |
||||
</remote-repository> |
||||
<remote-repository> |
||||
<option name="id" value="jboss.community" /> |
||||
<option name="name" value="JBoss Community repository" /> |
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> |
||||
</remote-repository> |
||||
</component> |
||||
</project> |
@ -0,0 +1,13 @@ |
||||
<component name="libraryTable"> |
||||
<library name="Maven: org.projectlombok:lombok:1.18.22"> |
||||
<CLASSES> |
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22.jar!/" /> |
||||
</CLASSES> |
||||
<JAVADOC> |
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22-javadoc.jar!/" /> |
||||
</JAVADOC> |
||||
<SOURCES> |
||||
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.22/lombok-1.18.22-sources.jar!/" /> |
||||
</SOURCES> |
||||
</library> |
||||
</component> |
@ -1,5 +1,12 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="MavenProjectsManager"> |
||||
<option name="originalFiles"> |
||||
<list> |
||||
<option value="$PROJECT_DIR$/vegetables/pom.xml" /> |
||||
</list> |
||||
</option> |
||||
</component> |
||||
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK"> |
||||
<output url="file://$PROJECT_DIR$/out" /> |
||||
</component> |
||||
|
@ -0,0 +1,25 @@ |
||||
<?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>vegetables</groupId> |
||||
<artifactId>vegetables</artifactId> |
||||
<version>0.0.0</version> |
||||
|
||||
<properties> |
||||
<maven.compiler.source>8</maven.compiler.source> |
||||
<maven.compiler.target>8</maven.compiler.target> |
||||
</properties> |
||||
<dependencies> |
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
<version>1.18.22</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
|
||||
</dependencies> |
||||
</project> |
@ -0,0 +1,4 @@ |
||||
大白菜 1.4 1.7 2.0 2022-03-24 00:00:00 |
||||
大白菜 2.5 2.6 2.7 2022-03-24 00:00:00 |
||||
娃娃菜 1.5 1.6s5 1.8 2022-03-24 00:00:00 |
||||
小白菜 1.2 1.35 1.5 2022-03-24 00:00:00 |
@ -0,0 +1,7 @@ |
||||
package me.lensfrex.vegetables.exceptions; |
||||
|
||||
public class SourceDataWornException extends Exception { |
||||
public SourceDataWornException(String message) { |
||||
super(message); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package me.lensfrex.vegetables.resopnse; |
||||
|
||||
public class ResponseGenerator { |
||||
/** |
||||
* 构建请求成功的响应返回类 |
||||
* @param data 请求到的数据 |
||||
* @param <T> 请求的数据类型 |
||||
* @return 构建出的请求响应类 |
||||
*/ |
||||
public static <T> UnityResponse<T> success(T data) { |
||||
return new UnityResponse<>(ResultStatus.SUCCESS, data); |
||||
} |
||||
|
||||
/** |
||||
* 构建请求失败的响应返回类 |
||||
* @param resultStatus 指定状态信息 |
||||
* @return 构建出的请求响应类 |
||||
*/ |
||||
public static <T> UnityResponse<T> error(ResultStatus resultStatus) { |
||||
return new UnityResponse<>(resultStatus, null); |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
package me.lensfrex.vegetables.resopnse; |
||||
|
||||
public enum ResultStatus { |
||||
SUCCESS(200, "成功!"), |
||||
|
||||
EMPTY_DATA(0, "数据是空的"), |
||||
PAGE_OUT_OF_RANGE(100, "请求的页码超过最大值"), |
||||
PAGE_PARAM_WORN(101, "分页参数有误"), |
||||
SOURCE_DATA_WORN(404, "源数据有错误,分页读取失败"), |
||||
UNKNOWN_ERROR(503, "未知错误"); |
||||
|
||||
/** |
||||
* 返回码。其值为ResultCode中定义的常量 |
||||
*/ |
||||
private final int code; |
||||
|
||||
/** |
||||
* 返回的结果信息 |
||||
*/ |
||||
private final String message; |
||||
|
||||
ResultStatus(int code, String message) { |
||||
this.code = code; |
||||
this.message = message; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "code: " + code + ", " + |
||||
"msg: '" + message + '\''; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
package me.lensfrex.vegetables.resopnse; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 统一的返回数据结构,含有字段code, message, data |
||||
* |
||||
* @param <T> data的类型 |
||||
*/ |
||||
@Data |
||||
public class UnityResponse<T> { |
||||
|
||||
/** |
||||
* 请求处理的状态信息 |
||||
*/ |
||||
private final ResultStatus resultStatus; |
||||
|
||||
/** |
||||
* 请求的数据,其类型为声明返回类时指定的类型 |
||||
*/ |
||||
private T data; |
||||
|
||||
public UnityResponse(ResultStatus resultCodes, T data) { |
||||
this.resultStatus = resultCodes; |
||||
this.data = data; |
||||
} |
||||
|
||||
public UnityResponse() { |
||||
resultStatus = ResultStatus.EMPTY_DATA; |
||||
this.data = null; |
||||
} |
||||
|
||||
// 手动拼成类似json的格式...
|
||||
// 当然真正生成json还是看gson之类专门的库吧...
|
||||
@Override |
||||
public String toString() { |
||||
return "{" + resultStatus + |
||||
", data: " + data + |
||||
'}'; |
||||
} |
||||
} |
@ -1,24 +0,0 @@ |
||||
package me.lensfrex.vegetables.resopnse; |
||||
|
||||
public class ResponseTool { |
||||
/** |
||||
* 构建请求成功的响应返回类 |
||||
* @param data 请求到的数据 |
||||
* @param message 请求信息 |
||||
* @param <T> 请求的数据类型 |
||||
* @return 构建出的请求响应类 |
||||
*/ |
||||
public static <T> UnityResponse<T> success(T data, String message) { |
||||
return new UnityResponse<>(UnityResponse.ResultCode.SUCCESS, message, data); |
||||
} |
||||
|
||||
/** |
||||
* 构建请求失败的响应返回类 |
||||
* @param message 失败信息 |
||||
* @param code 失败状态码,应从UnityResponse.ResultCode中定义的常量中选择 |
||||
* @return 构建出的请求响应类 |
||||
*/ |
||||
public static <T> UnityResponse<T> error(String message, int code) { |
||||
return new UnityResponse<>(code, message, null); |
||||
} |
||||
} |
@ -1,94 +0,0 @@ |
||||
package me.lensfrex.vegetables.resopnse; |
||||
|
||||
/** |
||||
* 统一的返回数据结构,含有字段code, message, data |
||||
* |
||||
* @param <T> data的类型 |
||||
*/ |
||||
public class UnityResponse<T> { |
||||
/** |
||||
* 返回码。其值为ResultCode中定义的常量 |
||||
*/ |
||||
private int code; |
||||
/** |
||||
* 返回的结果信息 |
||||
*/ |
||||
private String message; |
||||
/** |
||||
* 请求的数据,其类型为声明返回类时指定的类型 |
||||
*/ |
||||
private T data; |
||||
|
||||
public UnityResponse(int code, String message, T data) { |
||||
this.code = code; |
||||
this.message = message; |
||||
this.data = data; |
||||
} |
||||
|
||||
public UnityResponse() { |
||||
this.code = ResultCode.EMPTY_DATA; |
||||
this.message = "数据未初始化"; |
||||
this.data = null; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(int 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; |
||||
} |
||||
|
||||
// 手动拼成json格式...
|
||||
// 当然真正生成json还是看gson之类的吧...
|
||||
@Override |
||||
public String toString() { |
||||
return "{" + |
||||
"code=" + code + |
||||
", message='" + message + '\'' + |
||||
", data=" + data + |
||||
'}'; |
||||
} |
||||
|
||||
/** |
||||
* 状态码的常量 |
||||
*/ |
||||
public static class ResultCode { |
||||
/** |
||||
* 请求成功 |
||||
*/ |
||||
public static final int SUCCESS = 200; |
||||
/** |
||||
* 数据是空的 |
||||
*/ |
||||
public static final int EMPTY_DATA = 0; |
||||
/** |
||||
* 请求的分页页码超过最大值 |
||||
*/ |
||||
public static final int PAGE_OUT_OF_MAX = 100; |
||||
/** |
||||
* 请求的分页参数有误 |
||||
*/ |
||||
public static final int PAGE_PARAM_WORN = 101; |
||||
/** |
||||
* 未知错误 |
||||
*/ |
||||
public static final int UNKNOWN_ERROR = 503; |
||||
} |
||||
} |
@ -1,11 +1,16 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="JAVA_MODULE" version="4"> |
||||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||
<exclude-output /> |
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> |
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> |
||||
<output url="file://$MODULE_DIR$/target/classes" /> |
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> |
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/target" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.22" level="project" /> |
||||
</component> |
||||
</module> |
Loading…
Reference in new issue