static/404.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="text" style="text-align: center">
404,主人, 我累了, 让我休息一会!!!
</div>
</body>
</html>
package cn.stevekung.error;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
/*
常用HttpStatus状态:
HttpStatus.OK = 200;
HttpStatus.BADREQUEST = 400;
HttpStatus.FORBIDDEN = 403;
HttpStatus.NOTFOUND = 404;
HttpStatus.TIMEOUT = 408;
HttpStatus.INTERNAL_SERVER_ERROR = 500;
'401' : 'Unauthorized', //未经授权
*/
@Configuration
public class ErrorPageConfig {
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
return (container -> {
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
container.addErrorPages(error404Page, error401Page, error500Page);
});
}
}
更多推荐
自定义错误页面 404.html
发布评论