访问应用下不存在的路径或者触发 500 错误,都会走到这个页面,占位符显示对应的信息比如状态码404/500等等。 其它可能出现的问题 1.放到了/templates/下面却重定向到了 Tomcat 的 404 页面 说明视图没有解析到,检查控制层返回的视图是否有对应的视图提示,要么是页面的位置不对,要么是没引入Thymeleaf依赖 当视图没有...
1.项目配置 application.properties View Code pom.xml 1 2 3 4 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> PageController.java 1 2 3 4 5 6 @Controller publicclassPageController{ @RequestMapping("/index") publicSt...
今天刚刚接触Spring Boot框架技术,安装网上的教程做了一个Hello World的测试项目,但是不知道为什么,访问静态资源和json数据都没问题,但是访问template模板界面的时候却不行,浏览器返回404错误代码。 项目路径截图 在templates目录下添加了一个template模板文件: <!DOCTYPE html> Hello World 最主要的Controller...
今天刚刚接触Spring Boot框架技术,安装网上的教程做了一个Hello World的测试项目,但是不知道为什么,访问静态资源和json数据都没问题,但是访问template模板界面的时候却不行,浏览器返回404错误代码。 项目路径截图 在templates目录下添加了一个template模板文件: <!DOCTYPE html> Hello World 最主要的Controller...
1.准备页面404.html,并将它放在templates目录下面 2.写一个配置类,并且实现接口EmbeddedServletContainerCustomizer ,如下: importorg.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;importorg.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;importorg.springframework.boot.web...
定义404错误页的步骤 创建404错误页面:首先,我们需要创建一个HTML页面,作为我们的404错误页面。我们可以将这个页面命名为404.html,并将其放在src/main/resources/templates目录下。 配置404错误处理器:接下来,我们需要配置Spring Boot的404错误处理器。我们可以通过创建一个@ControllerAdvice注解的类来实现这一点。
spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.html 处理404错误: 最后,你需要在Spring Boot应用中处理404错误。可以通过创建一个全局异常处理器来实现这一点。例如,可以在@ControllerAdvice类中添加一个方法来处理404错误: @ControllerAdvicepublicclassGlobalExceptionHandler{@ExceptionHandler(NoHa...
一、准备好静态页面(bootstrap中文网很多) 二、创建一个SpringBoot工程,加入Web、Thymeleaf依赖。 三、引入静态资源,页面放在templates文件夹下,*.js、*.css和图片放在static文件夹下 四、修改页面,因为使用了Thymeleaf模板引擎,为了保证正常使用时有提示,在页面html标签中加入 ...
在使用 thymeleaf 等模板引擎时,SpringBoot 会自动到 src/main/resources/templates/error/,文件夹下寻找 404.html、500.html 的错误提示页面 错误提示页面的命名规则就是:错误码.html,如 404 是 404.html,500 是 500.html 1.2 没有使用模板引擎 如果没有使用 thymeleaf 等模板引擎时,SpringBoot 会到静态资源...
错误提示页面的命名规则就是:错误码.html,如 404 是 404.html,500 是 500.html 使用示例 创建springboot 项目如下 404、500 错误提示页面结构如下 application.properties 项目配置文件 server.port=8080 #它的默认值就是classpath:/templates/,源码在ThymeleafProperties类中 ...