From 2f55cebbad3dea187a5f91d16ec80a9677dab699 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 11:16:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/utils/AjaxResult.java | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 180 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/yssh/utils/AjaxResult.java b/src/main/java/com/yssh/utils/AjaxResult.java new file mode 100644 index 0000000..ff1b82e --- /dev/null +++ b/src/main/java/com/yssh/utils/AjaxResult.java @@ -0,0 +1,180 @@ +package com.yssh.utils; + +import java.util.HashMap; + +public class AjaxResult extends HashMap<String, Object> { + private static final long serialVersionUID = 1L; + + /** 鐘舵�佺爜 */ + public static final String CODE_TAG = "code"; + + /** 杩斿洖鍐呭 */ + public static final String MSG_TAG = "msg"; + + /** 鏁版嵁瀵硅薄 */ + public static final String DATA_TAG = "data"; + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄锛屼娇鍏惰〃绀轰竴涓┖娑堟伅銆� + */ + public AjaxResult() { + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄 + * + * @param code + * 鐘舵�佺爜 + * @param msg + * 杩斿洖鍐呭 + */ + public AjaxResult(int code, String msg) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + } + + /** + * 鍒濆鍖栦竴涓柊鍒涘缓鐨� AjaxResult 瀵硅薄 + * + * @param code + * 鐘舵�佺爜 + * @param msg + * 杩斿洖鍐呭 + * @param data + * 鏁版嵁瀵硅薄 + */ + public AjaxResult(int code, String msg, Object data) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + if (StringUtils.isNotNull(data)) { + super.put(DATA_TAG, data); + } + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success() { + return AjaxResult.success("鎿嶄綔鎴愬姛"); + } + + /** + * 杩斿洖鎴愬姛鏁版嵁 + * + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(Object data) { + return AjaxResult.success("鎿嶄綔鎴愬姛", data); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(String msg) { + return AjaxResult.success(msg, null); + } + + /** + * 杩斿洖鎴愬姛娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @param data + * 鏁版嵁瀵硅薄 + * @return 鎴愬姛娑堟伅 + */ + public static AjaxResult success(String msg, Object data) { + return new AjaxResult(HttpStatus.SUCCESS, msg, data); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @return 璀﹀憡娑堟伅 + */ + public static AjaxResult warn(String msg) { + return AjaxResult.warn(msg, null); + } + + /** + * 杩斿洖璀﹀憡娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @param data + * 鏁版嵁瀵硅薄 + * @return 璀﹀憡娑堟伅 + */ + public static AjaxResult warn(String msg, Object data) { + return new AjaxResult(HttpStatus.WARN, msg, data); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @return 閿欒娑堟伅 + */ + public static AjaxResult error() { + return AjaxResult.error("鎿嶄綔澶辫触"); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @return 閿欒娑堟伅 + */ + public static AjaxResult error(String msg) { + return AjaxResult.error(msg, null); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param msg + * 杩斿洖鍐呭 + * @param data + * 鏁版嵁瀵硅薄 + * @return 閿欒娑堟伅 + */ + public static AjaxResult error(String msg, Object data) { + return new AjaxResult(HttpStatus.ERROR, msg, data); + } + + /** + * 杩斿洖閿欒娑堟伅 + * + * @param code + * 鐘舵�佺爜 + * @param msg + * 杩斿洖鍐呭 + * @return 閿欒娑堟伅 + */ + public static AjaxResult error(int code, String msg) { + return new AjaxResult(code, msg, null); + } + + /** + * 鏂逛究閾惧紡璋冪敤 + * + * @param key + * 閿� + * @param value + * 鍊� + * @return 鏁版嵁瀵硅薄 + */ + @Override + public AjaxResult put(String key, Object value) { + super.put(key, value); + return this; + } +} -- Gitblit v1.9.3