Springboot首页
在springboot源码中定义了index.html可以默认访问,源码剖析中index.html只能放置在public、static、resources文件夹下,可以直接访问,所以在项目中,一般都会把首页放置在这三个文件夹中;
在templates文件夹下也可以放置index.html页面,但是templates文件夹下的页面只能通过controller层才能访问,大多数注重安全的项目则会将index.html页面放置在template文件夹下
源码剖析
目录结构
结果示例
在templates文件夹下放置index.html
第一步:配置controller
/**
* @Description
* @Date 2021/1/9
**/
@Controller
public class IndexController {
@RequestMapping("/")
public String indexTest(){
return "index";
}
}
第二步:需导入themeleaf依赖
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
第三步:将index.html页面放置在templates文件夹下
SpringBoot图标
我们浏览一个网站的时候,后端是可以修改网站图标的(仅限于springboot2.0版本之前可以修改)
# 关闭默认图标
spring:
mvc:
favicon:
enabled: false
将要放置的图标改名为favicon.ico,放置到public文件夹下