huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
1
2
3
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.ruoyi.common.core.domain;
 
 
import com.alibaba.fastjson2.JSONObject;
 
/**
 * 返回工具
 */
public class ResponseUtils {
 
 
    public static <T> BaseResult<T> successResponse(T obj) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(obj);
        response.setCode(200);
        response.setMsg("成功");
        return response;
    }
 
    public static <T> BaseResult<T> successResponse(String msg) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(null);
        response.setCode(200);
        response.setMsg(msg);
        return response;
    }
 
    public static <T> BaseResult<T> successResponse(T obj, String msg) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(obj);
        response.setCode(200);
        response.setMsg(msg);
        return response;
    }
 
    public static BaseResult<Object> successResponse() {
        BaseResult<Object> response = new BaseResult<>();
        response.setCode(200);
        response.setMsg("成功");
        response.setData(new JSONObject());
        return response;
    }
 
 
    public static <T> BaseResult<T> errorResponse(T obj, String msg) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(obj);
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }
 
    public static <T> BaseResult<T> errorResponse(Integer code,String msg) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(null);
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
 
    public static <T> BaseResult<T> errorResponse(String msg) {
        BaseResult<T> response = new BaseResult<>();
        response.setData(null);
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }
 
    public static <T> BaseResult<T> errorResponse() {
        BaseResult<T> response = new BaseResult<>();
        response.setData(null);
        response.setCode(500);
        response.setMsg("失败");
        return response;
    }
 
}