PageResult.java
1.7 KB
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
package com.wondertek.util;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.enums.GlobalCodeEnum;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PageResult<T> {
/**
* 信息代码
*/
private String code;
/**
* 信息说明
*/
private String msg;
/**
* 返回数据或jqgrid中的root
*/
private PageDTO result;
public <K> PageResult() {
}
public PageResult(String code, String msg) {
this.code = code;
this.msg = msg;
}
public PageResult(String code, String msg, PageDTO result) {
this.code = code;
this.msg = msg;
this.result = result;
}
public static <T> PageResult<T> ok() {
return new PageResult<>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg());
}
public static <T> PageResult<T> ok(PageDTO result) {
return new PageResult<T>(GlobalCodeEnum.SUCCESS.getCode(), GlobalCodeEnum.SUCCESS.getMsg(), result);
}
public boolean isSuccess() {
return GlobalCodeEnum.SUCCESS.getCode().equals(this.code);
}
public static <T> PageResult<T> error() {
return new PageResult<T>(GlobalCodeEnum.FAILURE.getCode(), GlobalCodeEnum.FAILURE.getMsg());
}
public static <T> PageResult<T> error(String msg) {
return new PageResult<T>(GlobalCodeEnum.FAILURE.getCode(), msg);
}
public static <T> PageResult<T> error(String code, String msg) {
return new PageResult<T>(code, msg);
}
public static <K> PageResult<K> error(String code, String msg, PageDTO k) {
return new PageResult<K>(code, msg, k);
}
}