如题

1
2
3
4
5
6
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Aug 15 14:29:58 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

添加一个 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
33
package 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;

@Controller
public class SiteErrorController implements ErrorController {
@RequestMapping("/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";
}
}

@Override
public String getErrorPath() {
return "/error";
}
}