发布于 

java,统一接口异常

在Controller包下添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


import com.example.rcadmin.commonutils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class)
public R exception(Exception e) {
e.printStackTrace();
return R.error().message(e.getMessage());
}
}