常用的Ajax返回值封装设计



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
package cn.blue.model;

import java.util.HashMap;

/**
* 用于ajax
*
* @author Blue
*
*/
public class Result extends HashMap<String, Object> {

private static final long serialVersionUID = 1L;

private Result() {
}

public static Result success() {
return new Result().setCode(0);
}

public static Result error(int code) {
return new Result().setCode(code);
}

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

public Result setCode(int code) {
this.put("code", code);
return this;
}

public int getCode() {
return this.getValue("code");
}

public Result setMsg(String msg) {
this.put("msg", msg);
return this;
}

public String getMsg() {
return this.getValue("msg");
}

public <T> T getValue(String key) {
return (T) this.get(key);
}
}
打赏
  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  1. © 2020 Liu Yang    湘ICP备20003709号

请我喝杯咖啡吧~

支付宝
微信