From c93bdeb8ed528d015865f763dfc240cbad7aa00b Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期三, 05 六月 2024 11:45:08 +0800 Subject: [PATCH] feat:题目表移除分数字段 --- src/main/java/com/ycl/jxkg/base/Result.java | 68 ++++++++++++++++++++++++--------- 1 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/base/Result.java b/src/main/java/com/ycl/jxkg/base/Result.java index 5b121fe..32ede1a 100644 --- a/src/main/java/com/ycl/jxkg/base/Result.java +++ b/src/main/java/com/ycl/jxkg/base/Result.java @@ -1,15 +1,17 @@ package com.ycl.jxkg.base; +import java.util.HashMap; + /** * @version 3.3.0 * @description: The type Rest response. * Copyright (C), 2020-2024, 姝︽眽鎬濈淮璺宠穬绉戞妧鏈夐檺鍏徃 * @date 2021/5/25 10:45 */ -public class Result<T> { - private int code; - private String message; - private T response; +public class Result<T> extends HashMap<String, Object> { + + public Result() { + } /** * Instantiates a new Rest response. @@ -18,8 +20,8 @@ * @param message the message */ public Result(int code, String message) { - this.code = code; - this.message = message; + this.put("code", code); + this.put("message", message); } /** @@ -29,10 +31,12 @@ * @param message the message * @param response the response */ - public Result(int code, String message, T response) { - this.code = code; - this.message = message; - this.response = response; + public static Result response(int code, String message, Object response) { + Result restResponse = new Result(); + restResponse.put("code", code); + restResponse.put("message", message); + restResponse.put("data", response); + return restResponse; } /** @@ -43,7 +47,10 @@ * @return the rest response */ public static Result fail(Integer code, String msg) { - return new Result<>(code, msg); + Result restResponse = new Result(); + restResponse.put("code", code); + restResponse.put("message", msg); + return restResponse; } /** @@ -53,7 +60,10 @@ */ public static Result ok() { SystemCode systemCode = SystemCode.OK; - return new Result<>(systemCode.getCode(), systemCode.getMessage()); + Result restResponse = new Result(); + restResponse.put("code", systemCode.getCode()); + restResponse.put("message", systemCode.getMessage()); + return restResponse; } /** @@ -65,7 +75,11 @@ */ public static <F> Result<F> ok(F response) { SystemCode systemCode = SystemCode.OK; - return new Result<>(systemCode.getCode(), systemCode.getMessage(), response); + Result restResponse = new Result(); + restResponse.put("code", systemCode.getCode()); + restResponse.put("message", systemCode.getMessage()); + restResponse.put("data", response); + return restResponse; } /** @@ -74,7 +88,7 @@ * @return the code */ public int getCode() { - return code; + return (int) this.get("code"); } /** @@ -83,7 +97,7 @@ * @param code the code */ public void setCode(int code) { - this.code = code; + this.put("code", code); } /** @@ -92,7 +106,7 @@ * @return the message */ public String getMessage() { - return message; + return (String) this.get("message"); } /** @@ -101,7 +115,7 @@ * @param message the message */ public void setMessage(String message) { - this.message = message; + this.put("message", message); } /** @@ -110,7 +124,7 @@ * @return the response */ public T getResponse() { - return response; + return (T) this.get("data"); } /** @@ -119,6 +133,22 @@ * @param response the response */ public void setResponse(T response) { - this.response = response; + this.put("data", response); + } + + @Override + public Result<T> put(String key, Object value) { + super.put(key, value); + return this; + } + + public Result data(Object data) { + super.put("data", data); + return this; + } + + public Result total(Long total) { + super.put("total", total); + return this; } } -- Gitblit v1.8.0