请问springboot2.0中,怎么自定义404,500等错误页面呢
这里有一个Baidu说明链接,你可以看看,希望对你有帮助!
https://jingyan.baidu.com/article/00a07f380cb40f82d028dcac.html
我现在是通过这种方式实现的,大家有更好的方法的话希望分享
@Controller
public class MyErrorController implements ErrorController {
private static final String PATH = "/error";
@RequestMapping(value = PATH)
private String error(HttpServletRequest request, HttpServletResponse response) {
int httpStatus=response.getStatus();
HttpHeaders httpHeaders = new HttpHeaders();
/*Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
httpHeaders.add(key, value);
}*/
switch (httpStatus){
case ResponseCodeConstant.CODE_404:
return ErrorConstant.ERROR_404_PATH;
default:
break;
}
return ErrorConstant.ERROR_500_PATH;
}
@Override
public String getErrorPath() {
return PATH;
}
}