统一响应对象
This commit is contained in:
parent
cbd23f86b3
commit
8de9a52875
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.axzo.framework</groupId>
|
<groupId>cn.axzo.framework</groupId>
|
||||||
<artifactId>common-common</artifactId>
|
<artifactId>common-common</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.5</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package cn.azxo.framework.common.logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务日志模板回调
|
||||||
|
*
|
||||||
|
* @author zhaoyong
|
||||||
|
* @see JobLoggerCallback
|
||||||
|
* @since 2021-05-20 19:20
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface JobLoggerCallback<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务操作
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
T doInExecute();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package cn.azxo.framework.common.logger;
|
||||||
|
|
||||||
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时傻日志模板类
|
||||||
|
*
|
||||||
|
* @author zhaoyong
|
||||||
|
* @see JobLoggerTemplate
|
||||||
|
* @since 2021-06-17 19:35
|
||||||
|
*/
|
||||||
|
public class JobLoggerTemplate {
|
||||||
|
|
||||||
|
public <T> T execute(String mdcKey, JobLoggerCallback<T> action){
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
MDC.put(mdcKey, uuid);
|
||||||
|
try {
|
||||||
|
return action.doInExecute();
|
||||||
|
} finally {
|
||||||
|
MDC.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,25 +18,25 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CommonResponse<T> {
|
public class CommonResponse<T> {
|
||||||
|
|
||||||
private String code;
|
private Integer code;
|
||||||
|
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
public static CommonResponse success(Object data) {
|
public static CommonResponse success(Object data) {
|
||||||
return new CommonResponse("200", "success", null);
|
return new CommonResponse(200, "success", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommonResponse success(String code, String message, Object data) {
|
public static CommonResponse success(Integer code, String message, Object data) {
|
||||||
return new CommonResponse(code, message, data);
|
return new CommonResponse(code, message, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommonResponse error(String code, String message){
|
public static CommonResponse error(Integer code, String message){
|
||||||
return new CommonResponse(code, message, null);
|
return new CommonResponse(code, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommonResponse error(String code, String message, Object data){
|
public static CommonResponse error(Integer code, String message, Object data){
|
||||||
return new CommonResponse(code, message, data);
|
return new CommonResponse(code, message, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user