zoukankan      html  css  js  c++  java
  • 接口统一返回类

    package top.dj.entity;
    
    import org.springframework.http.HttpStatus;
    
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * @Author: DengJia
     * @Date: 2021/9/27 15:30
     * @Description: 通用返回
     */
    
    public class R extends HashMap<String, Object> {
        private static final long serialVersionUID = 1L;
    
        public R() {
            put("code", 0);
            put("msg", "success");
        }
    
        public static R error() {
            return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "未知异常,请联系管理员!");
        }
    
        public static R error(String msg) {
            return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
        }
    
        public static R error(int code, String msg) {
            R r = new R();
            r.put("code", code);
            r.put("msg", msg);
            return r;
        }
    
        public static R errorData(Object obj) {
            R r = new R();
            r.put("errorData", obj);
            return r;
        }
    
        public static R ok() {
            return new R();
        }
    
        public static R ok(String msg) {
            R r = new R();
            r.put("msg", msg);
            return r;
        }
    
        public static R ok(int code, String msg) {
            R r = new R();
            r.put("code", code);
            r.put("msg", msg);
            return r;
        }
    
        public static R ok(Map<String, Object> map) {
            R r = new R();
            r.putAll(map);
            return r;
        }
    
        public static R data(Object obj) {
            R r = new R();
            r.put("data", obj);
            return r;
        }
    
        public static R data(String msg, Object obj) {
            R r = new R();
            r.put("msg", msg);
            r.put("data", obj);
            return r;
        }
    
        @Override
        public Object put(String key, Object value) {
            super.put(key, value);
            return this;
        }
    
        public Object getCode() {
            return super.get("code");
        }
    }
    
    DJOSIMON
  • 相关阅读:
    Linux的用户和组的属性
    Linux文件/目录 的新建、复制、移动(更名)、删除、查看、压缩命令
    排序算法和实现
    面试-三三原则
    phpstudy 最新版linux 面板 web防火墙后门防护功能教程
    小白必看的Python爬虫流程
    Python3迭代器与生成器
    python的异常处理机制
    python变量的作用域
    值得收藏的Python第三方库
  • 原文地址:https://www.cnblogs.com/DJOSIMON/p/15343246.html
Copyright © 2011-2022 走看看