| | |
| | | package com.mindskip.xzs.base; |
| | | |
| | | /** |
| | | * @version 3.3.0 |
| | | * @description: The type Rest response. |
| | | * Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司 |
| | | * @date 2021/5/25 10:45 |
| | | */ |
| | | public class RestResponse<T> { |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class RestResponse<T> extends HashMap<String, Object> { |
| | | private int code; |
| | | private String message; |
| | | private T response; |
| | |
| | | * @param message the message |
| | | */ |
| | | public RestResponse(int code, String message) { |
| | | this.code = code; |
| | | this.message = message; |
| | | this.put("code", code); |
| | | this.put("message", message); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param message the message |
| | | * @param response the response |
| | | */ |
| | | public RestResponse(int code, String message, T response) { |
| | | this.code = code; |
| | | this.message = message; |
| | | this.response = response; |
| | | public static RestResponse response(int code, String message, Object response) { |
| | | RestResponse restResponse = new RestResponse(); |
| | | restResponse.put("code", code); |
| | | restResponse.put("message", message); |
| | | restResponse.put("response", response); |
| | | return restResponse; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static <F> RestResponse<F> ok(F response) { |
| | | SystemCode systemCode = SystemCode.OK; |
| | | return new RestResponse<>(systemCode.getCode(), systemCode.getMessage(), response); |
| | | return RestResponse.response(systemCode.getCode(), systemCode.getMessage(), response); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return the code |
| | | */ |
| | | public int getCode() { |
| | | return code; |
| | | } |
| | | |
| | | /** |
| | | * Sets code. |
| | | * |
| | | * @param code the code |
| | | */ |
| | | public void setCode(int code) { |
| | | this.code = code; |
| | | return (int) this.get("code"); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return the message |
| | | */ |
| | | public String getMessage() { |
| | | return message; |
| | | return (String) this.get("message"); |
| | | } |
| | | |
| | | /** |
| | | * Sets message. |
| | | * |
| | | * @param message the message |
| | | */ |
| | | public void setMessage(String message) { |
| | | this.message = message; |
| | | } |
| | | |
| | | /** |
| | | * Gets response. |
| | |
| | | * @return the response |
| | | */ |
| | | public T getResponse() { |
| | | return response; |
| | | } |
| | | |
| | | /** |
| | | * Sets response. |
| | | * |
| | | * @param response the response |
| | | */ |
| | | public void setResponse(T response) { |
| | | this.response = response; |
| | | return (T) this.get("response"); |
| | | } |
| | | |
| | | public RestResponse() { |
| | | } |
| | | |
| | | @Override |
| | | public RestResponse put(String key, Object value) { |
| | | super.put(key, value); |
| | | return this; |
| | | } |
| | | } |