SpringBoot使用thymeleaf跳转页面时提示404怎么解决
温馨提示:这篇文章已超过708天没有更新,请注意相关的内容是否还可用!
想构建简单页面跳转,正常跳转index.html,404和500跳转到专门的页面,配置正确,路径也正确,controller的方法也能访问到,但是一直无法正常跳转,页面报404.修改版本后,可以正常访问。
修改前:
@Controllerpublic class IndexController { @GetMapping("/") public String index() {// int i = 9 / 0; System.out.println("HelloWorld!"); return "index"; } }
访问:localhos:8080,报错:404
记录一下目前可以正常使用的版本
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>3.0.0</thymeleaf-layout-dialect.version> </properties>
修改后:
Controller(index):
@Controllerpublic class IndexController { @GetMapping("/") public String index() {// int i = 9 / 0; return "index"; } }
Controller(500):
@Controllerpublic class IndexController { @GetMapping("/") public String index() { int i = 9 / 0; return "index"; } }
测试404只需在导航栏输入不存在的路径,例如:http://localhost:8080/aaaa