From 5e873863bc7324894c89b0a0fc77a6202c91cd64 Mon Sep 17 00:00:00 2001 From: wzp <516075396@qq.com> Date: 星期二, 06 四月 2021 10:35:42 +0800 Subject: [PATCH] 20210406 --- src/main/java/com/ots/project/exam/dto/RestResponse.java | 31 ++----------------------------- 1 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/ots/project/exam/dto/RestResponse.java b/src/main/java/com/ots/project/exam/dto/RestResponse.java index 871c0fa..daa0510 100644 --- a/src/main/java/com/ots/project/exam/dto/RestResponse.java +++ b/src/main/java/com/ots/project/exam/dto/RestResponse.java @@ -1,51 +1,32 @@ package com.ots.project.exam.dto; - import com.ots.common.enums.ResponseCode; import com.ots.common.enums.SystemCode; import com.ots.project.common.exception.BaseException; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DuplicateKeyException; -/** - * @author Shawn - */ @Slf4j public class RestResponse<T> { private int code; private String message; private T response; - public RestResponse(int code, String message) { this.code = code; this.message = message; } - public RestResponse(int code, String message, T response) { this.code = code; this.message = message; this.response = response; } - public static RestResponse fail(Integer code, String msg) { return new RestResponse<>(code, msg); } - - /** - * 澧炲姞閿欒缂栫爜缁熶竴澶勭悊 - * - * @param enumCode - * @return - */ + public static RestResponse fail(ResponseCode enumCode) { return new RestResponse<>(enumCode.getCode(), enumCode.getMessage()); } - - /** - * 寮傚父缁撳悎鏋氫妇鏂逛究寮傚父缁熶竴澶勭悊 - * - * @param e - * @return - */ + public static RestResponse fail(Exception e) { if (e instanceof BaseException) { BaseException e1 = (BaseException) e; @@ -57,37 +38,29 @@ return new RestResponse<>(999, e.getMessage()); } } - public static RestResponse ok() { SystemCode systemCode = SystemCode.OK; return new RestResponse<>(systemCode.getCode(), systemCode.getMessage()); } - public static <F> RestResponse<F> ok(F response) { SystemCode systemCode = SystemCode.OK; return new RestResponse<>(systemCode.getCode(), systemCode.getMessage(), response); } - 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 getResponse() { return response; } - public void setResponse(T response) { this.response = response; } -- Gitblit v1.9.1