From 5002a0e6f333a6e5ec7e94fdf0111586833a5ae6 Mon Sep 17 00:00:00 2001 From: tamguo Date: Tue, 7 Aug 2018 17:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tamguo/config/web/ErrorConfigurar.java | 21 +++++++++ .../java/com/tamguo/config/web/WebConfig.java | 1 - .../com/tamguo/web/tiku/IndexController.java | 14 +++++- .../src/main/resources/templates/404.html | 45 ++++++++++++++++--- .../src/main/resources/templates/500.html | 45 ++++++++++++++++--- 5 files changed, 112 insertions(+), 14 deletions(-) create mode 100644 tamguo-tms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java diff --git a/tamguo-tms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java b/tamguo-tms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java new file mode 100644 index 0000000..9267271 --- /dev/null +++ b/tamguo-tms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java @@ -0,0 +1,21 @@ +package com.tamguo.config.web; + +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; + +@Component +public class ErrorConfigurar implements ErrorPageRegistrar { + + @Override + public void registerErrorPages(ErrorPageRegistry registry) { + ErrorPage[] errorPages=new ErrorPage[2]; + errorPages[0]=new ErrorPage(HttpStatus.NOT_FOUND,"/error404"); + errorPages[1]=new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/error500"); + + registry.addErrorPages(errorPages); + } + +} diff --git a/tamguo-tms/src/main/java/com/tamguo/config/web/WebConfig.java b/tamguo-tms/src/main/java/com/tamguo/config/web/WebConfig.java index 6fd6968..1cb893f 100644 --- a/tamguo-tms/src/main/java/com/tamguo/config/web/WebConfig.java +++ b/tamguo-tms/src/main/java/com/tamguo/config/web/WebConfig.java @@ -31,5 +31,4 @@ public class WebConfig implements WebMvcConfigurer { public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/files/**").addResourceLocations("file:"+fileStoragePath); } - } diff --git a/tamguo-tms/src/main/java/com/tamguo/web/tiku/IndexController.java b/tamguo-tms/src/main/java/com/tamguo/web/tiku/IndexController.java index 35884fa..caabff0 100644 --- a/tamguo-tms/src/main/java/com/tamguo/web/tiku/IndexController.java +++ b/tamguo-tms/src/main/java/com/tamguo/web/tiku/IndexController.java @@ -13,7 +13,7 @@ public class IndexController { model.setViewName("index"); return model; } - + @RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView mainAction(ModelAndView model) { model.setViewName("index"); @@ -37,4 +37,16 @@ public class IndexController { model.setViewName("thirdparty/sogousiteverification"); return model; } + + @RequestMapping(value = "error404", method = RequestMethod.GET) + public ModelAndView error404(ModelAndView model) { + model.setViewName("404"); + return model; + } + + @RequestMapping(value = "error500", method = RequestMethod.GET) + public ModelAndView error500(ModelAndView model) { + model.setViewName("500"); + return model; + } } diff --git a/tamguo-tms/src/main/resources/templates/404.html b/tamguo-tms/src/main/resources/templates/404.html index dd556ed..814c569 100644 --- a/tamguo-tms/src/main/resources/templates/404.html +++ b/tamguo-tms/src/main/resources/templates/404.html @@ -1,12 +1,45 @@ - + -探果题库_资源不存在 - - + + + 探果题库_聪明的学生都在这里 + + + + + + + + + + + + + -访问的内容不存在! -返回首页 + +
+ +
+
+
+ 访问的内容不存在! + 返回首页 +
+
+
+ + +
+ + +
+ + + + + \ No newline at end of file diff --git a/tamguo-tms/src/main/resources/templates/500.html b/tamguo-tms/src/main/resources/templates/500.html index 6f68fca..c7c82ba 100644 --- a/tamguo-tms/src/main/resources/templates/500.html +++ b/tamguo-tms/src/main/resources/templates/500.html @@ -1,12 +1,45 @@ - + -探果题库_错误页面 - - + + + 探果题库_聪明的学生都在这里 + + + + + + + + + + + + + -服务器异常! -返回首页 + +
+ +
+
+
+ 服务器异常! + 返回首页 +
+
+
+ + +
+ + +
+ + + + + \ No newline at end of file