一. 不使用templates模板情况下
SpringBoot里面没有我们之前常规web开发的WebContent(WebApp),它只有src目录
在src/main/resources下面有两个文件夹,static和templates springboot默认 static中放静态页面,而templates中放动态页面
静态页面:
这里我们直接在static放一个index.html,然后直接输入http://localhost:8080/index.html便能成功访问到static中的index.html
(好像可以新建一个public文件夹,也可以放静态文件)
也可以通过controller跳转:
@RequestMapping(value = "/test23")
public String index() {
System.out.println("++++++++++++++++++");
return "index.html";
}
然后输入http://localhost:8080/test23就可以成功访问到static中的index.html
但是如果代码写成
@RequestMapping(value = "/test23")
public String index() {
System.out.println("++++++++++++++++++");
return "index";
}
或者
return "redirect.html"
或者
return "redirect:index"
然后输入http://localhost:8080/test23后都会报错404
那么现在application.yml中加上如下一代码
spring:
mvc:
view:
prefix: resources/static/
suffix: .html
重新进行以上的测试。
http://localhost:8080/index.html 这个地址直接访问的还是static下的index.html
return "index.html"; 页面访问http://localhost:8080/test23还是404
return "index"; 页面访问http://localhost:8080/test23还是404
return "redirect:index";页面访问http://localhost:8080/test23还是404
return "redirect.html";页面访问http://localhost:8080/test23还是404