-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #585 from shanwb/master
add common result
- Loading branch information
Showing
5 changed files
with
121 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>jcommon</artifactId> | ||
<groupId>run.mone</groupId> | ||
<version>1.4-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>infra-common</artifactId> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
</project> |
31 changes: 31 additions & 0 deletions
31
jcommon/infra-common/src/main/java/run/mone/common/ErrorCode.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,31 @@ | ||
/* | ||
* Copyright 2020 Xiaomi | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package run.mone.common; | ||
|
||
/** | ||
* @author shanwb | ||
* @date 2023-08-16 | ||
*/ | ||
public class ErrorCode { | ||
public static final int SUCCESS = 0; | ||
|
||
public static final int PARAM_ERROR = 400; | ||
public static final int INTERNAL_ERROR = 500; | ||
|
||
public ErrorCode() { | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
jcommon/infra-common/src/main/java/run/mone/common/Result.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,71 @@ | ||
/* | ||
* Copyright 2020 Xiaomi | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package run.mone.common; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author shanwb | ||
* @date 2023-08-16 | ||
*/ | ||
@Data | ||
public class Result<T> implements Serializable { | ||
private int code; | ||
private String message; | ||
private T data; | ||
private String traceId; | ||
private Map<String, String> attributes; | ||
|
||
public Result(int code, String message, T data) { | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
|
||
public Result(int code, String message, T data, String traceId) { | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
this.traceId = traceId; | ||
} | ||
|
||
public static <T> Result<T> success(T data) { | ||
return new Result(ErrorCode.SUCCESS, "success", data); | ||
} | ||
|
||
public static <T> Result<T> fail(int code, String message) { | ||
return new Result(code, message, null); | ||
} | ||
|
||
public static <T> Result<T> fromException(Throwable e) { | ||
return fail(ErrorCode.INTERNAL_ERROR, e.getMessage()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Result{" + | ||
"code=" + code + | ||
", message='" + message + '\'' + | ||
", data=" + data + | ||
", traceId='" + traceId + '\'' + | ||
", attributes=" + attributes + | ||
'}'; | ||
} | ||
} |
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
3 changes: 0 additions & 3 deletions
3
jcommon/test/src/main/java/com/xiaomi/youpin/test/codefilter/c/test-1.4-SNAPSHOT.jar
This file was deleted.
Oops, something went wrong.