通用结果类 Result

package com.zhongyuan.ota.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回结果数据
 */
public class Result extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public Result() {
        put("code", 0);
    }

    public static Result error() {
        return error(500, "未知异常,请联系管理员");
    }

    public static Result error(String msg) {
        return error(500, msg);
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.put("code", code);
        result.put("msg", msg);
        return result;
    }

    public static Result success() {
        return new Result();
    }
    
    public static Result success(String msg) {
        Result result = new Result();
        result.put("msg", msg);
        return result;
    }
    
    public static Result success(String msg, int total, Object object) {
        Result result = new Result();
        result.put("msg", msg);
        result.put("total", total);
        result.put("rows", object);
        return result;
    }

    public static Result success(Map<String, Object> map) {
        Result result = new Result();
        result.putAll(map);
        return result;
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}

 

posted @ 2018-03-30 10:09  zyg_Fatty  阅读(325)  评论(0编辑  收藏  举报