1 | Whitelabel Error Page |
添加一个 Controller,代码如下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
33package domain.controller;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
public class SiteErrorController implements ErrorController {
"/error") (
public String handleError(HttpServletRequest request) {
//获取statusCode:401,404,500
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
switch (statusCode) {
case 401:
case 403:
case 404:
return "/404";
case 500:
case 502:
return "/502";
default:
return "/502";
}
}
public String getErrorPath() {
return "/error";
}
}