From 93af1c6ffb9ae0e894689ad3a37b548e57d54cff Mon Sep 17 00:00:00 2001 From: linzhijie <19970921lzj> Date: 星期四, 11 三月 2021 19:10:07 +0800 Subject: [PATCH] 有注释的测评系统业务代码 --- src/main/java/com/ots/project/exam/dto/RestResponse.java | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 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 daa0510..871c0fa 100644 --- a/src/main/java/com/ots/project/exam/dto/RestResponse.java +++ b/src/main/java/com/ots/project/exam/dto/RestResponse.java @@ -1,32 +1,51 @@ 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; @@ -38,29 +57,37 @@ 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