张洋洋
2025-02-24 9804628abf554c3658345fc8fc9472cfb179fd5f
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
package com.se.simu.controller;
 
import com.se.simu.domain.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
 
@Slf4j
@SuppressWarnings("ALL")
public class BaseController {
    public <T> R<T> success(T data) {
        return new R<T>(HttpStatus.OK, data);
    }
 
    public <T> R<T> success(T data, String msg) {
        return new R<T>(HttpStatus.OK, data, msg);
    }
 
    public <T> R<T> success(T data, long count) {
        return new R<T>(HttpStatus.OK, data, count);
    }
 
    public <T> R<T> success(T data, long count, String msg) {
        return new R<T>(HttpStatus.OK, data, count, msg);
    }
 
    public <T> R<T> fail(T data) {
        return new R<T>(HttpStatus.INTERNAL_SERVER_ERROR, data);
    }
 
    public <T> R<T> fail(String msg, T data) {
        return new R<T>(HttpStatus.INTERNAL_SERVER_ERROR, data, msg);
    }
 
    public <T> R<T> fail(Exception ex) {
        log.error(ex.getMessage(), ex);
        return new R<T>(HttpStatus.INTERNAL_SERVER_ERROR, null, ex.getMessage());
    }
 
    public <T> R<T> fail(Exception ex, T data) {
        log.error(ex.getMessage(), ex);
        return new R<T>(HttpStatus.INTERNAL_SERVER_ERROR, data, ex.getMessage());
    }
}