2021与蓝度共同重构项目,服务端
chenjiantian
2021-11-24 6bdb5dda11b8723ddc20a37b9cbcc1e1fdace13a
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
package com.sandu.common.util;
 
import com.sandu.common.domain.CommonPage;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.enums.ResponseStatusEnums;
import org.springframework.web.servlet.ModelAndView;
 
import java.util.List;
import java.util.Map;
 
/**
 * 接口返回工具类,支持ModelAndView、ResponseVO、PageResult
 *
 * @author chenjiantian
 */
public class ResponseUtil {
 
    /**
     * 返回 失败
     */
    public static ResponseVO<Object> fail(String message) {
        return new ResponseVO<>(ResponseStatusEnums.FAIL.getCode(), message, null);
    }
 
    /**
     * 返回 成功
     */
    public static ResponseVO<Object> success(Object data) {
        return new ResponseVO<>(ResponseStatusEnums.SUCCESS.getCode(), ResponseStatusEnums.SUCCESS.getMessage(), data);
    }
 
    /**
     * 返回 分页成功
     */
    public static ResponseVO<Object> successPage(List<?> list) {
        return success(CommonPage.restPage(list));
    }
 
 
    public static ModelAndView view(String view) {
        return new ModelAndView(view);
    }
 
    public static ModelAndView view(String view, Map<String, Object> model) {
        return new ModelAndView(view, model);
    }
 
    public static ModelAndView redirect(String view) {
        return new ModelAndView("redirect:" + view);
    }
 
    public static ModelAndView forward(String view) {
        return new ModelAndView("forward:" + view);
    }
 
    public static ResponseVO<Object> error(int code, String message) {
        return new ResponseVO<>(code, message, null);
    }
 
    public static ResponseVO<Object> error(int code, String message, Object data) {
        return new ResponseVO<>(code, message, data);
    }
 
    public static ResponseVO<Object> error(int code, String message, Object data, String exception) {
        return new ResponseVO<>(code, message, data, exception);
    }
 
 
}