提交 | 用户 | 时间
|
a6de49
|
1 |
/** |
H |
2 |
* Copyright (c) 2016-2019 人人开源 All rights reserved. |
|
3 |
* |
|
4 |
* https://www.renren.io |
|
5 |
* |
|
6 |
* 版权所有,侵权必究! |
|
7 |
*/ |
|
8 |
|
|
9 |
package com.iailab.module.data.common.utils; |
|
10 |
|
|
11 |
import org.apache.http.HttpStatus; |
|
12 |
|
|
13 |
import java.util.HashMap; |
|
14 |
import java.util.Map; |
|
15 |
|
|
16 |
/** |
|
17 |
* 返回数据 |
|
18 |
* |
|
19 |
* @author Mark sunlightcs@gmail.com |
|
20 |
*/ |
|
21 |
public class R extends HashMap<String, Object> { |
|
22 |
private static final long serialVersionUID = 1L; |
|
23 |
|
|
24 |
public R() { |
|
25 |
put("code", 0); |
|
26 |
put("msg", "success"); |
|
27 |
} |
|
28 |
|
|
29 |
public static R error() { |
|
30 |
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员"); |
|
31 |
} |
|
32 |
|
|
33 |
public static R error(String msg) { |
|
34 |
return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg); |
|
35 |
} |
|
36 |
|
|
37 |
public static R error(int code, String msg) { |
|
38 |
R r = new R(); |
|
39 |
r.put("code", code); |
|
40 |
r.put("msg", msg); |
|
41 |
return r; |
|
42 |
} |
|
43 |
|
|
44 |
public static R ok(String msg) { |
|
45 |
R r = new R(); |
|
46 |
r.put("msg", msg); |
|
47 |
return r; |
|
48 |
} |
|
49 |
|
|
50 |
public static R ok(Map<String, Object> map) { |
|
51 |
R r = new R(); |
|
52 |
r.putAll(map); |
|
53 |
return r; |
|
54 |
} |
|
55 |
|
|
56 |
public static R ok() { |
|
57 |
return new R(); |
|
58 |
} |
|
59 |
|
|
60 |
public R put(String key, Object value) { |
|
61 |
super.put(key, value); |
|
62 |
return this; |
|
63 |
} |
|
64 |
} |