ResultUtils.java 2.29 KB
Newer Older
1 2 3
package cn.wisenergy.common.utils;

import cn.wisenergy.common.enums.ResultEnum;
m1991's avatar
m1991 committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

/**
 * 用于返回Result的工具类
 * Created by m1991 on 2021/2/28 23:03
 */
public class ResultUtils {

    /**
     * 统一返回成功的Result
     */
    public static Result returnSuccess() {
        Result Result = new Result(ResultEnum.SUCCESS);
        return Result;
    }

    /**
     * 统一返回成功的Result 带数据
     */
    public static Result returnSuccess(String msg, Object data) {
        Result Result = new Result(ResultEnum.SUCCESS.getCode(), msg, data);
        return Result;
    }

    /**
     * 统一返回成功的Result 不带数据
     */
    public static Result returnSuccess(String msg) {
        Result Result = new Result(ResultEnum.SUCCESS.getCode(), msg);
        return Result;
    }

    /**
     * 统一返回成功的Result 带数据 没有消息
     */
    public static Result returnDataSuccess(Object data) {
        Result Result = new Result(ResultEnum.SUCCESS);
        Result.setData(data);
        return Result;
    }

44 45 46 47 48 49 50 51 52 53 54 55 56
    /**
     * 用于返回唯一值
     * @param data
     * @param wyz
     * @return
     */
    public static Result returnDataSuccess(Object data,String wyz) {
        Result Result = new Result(ResultEnum.SUCCESS);
        Result.setData(data);
        Result.setWyz(wyz);
        return Result;
    }

m1991's avatar
m1991 committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    /**
     * 返回一个失败的Result
     * @return
     */
    public static Result returnFail() {
        Result Result = new Result(ResultEnum.FAIL);
        return Result;
    }

    /**
     * 返回一个失败的Result
     *
     * @param msg
     * @param code
     * @return
     */
    public static Result returnFail(String msg, String code) {
        Result Result = new Result(code, msg);
        return Result;
    }

    /**
     * 返回 一个失败的Result,code统一为 “1”,msg自定义
     *
     * @param msg
     * @return
     */
    public static Result returnFail(String msg) {
        Result Result = new Result(ResultEnum.FAIL.getCode(), msg);
        return Result;
    }

    /**
     * 根据枚举创建一个Result
     *
     * @param resultEnum
     * @return
     */
    public static Result returnResult(ResultEnum resultEnum) {
        Result Result = new Result(resultEnum);
        return Result;
    }
}