SpringBoot项目中访问HTML页面的三种方法
作者:nanxun___
这篇文章主要介绍了SpringBoot项目中访问HTML页面的三种方法,文中通过代码示例和图文结合的方式讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
一.将 index.html 作为首页面
1.静态首页
springboot项目启动后,默认会到静态资源 resources->static 目录下查找index.html页面

2.动态首页
在静态资源路径找不到 index.html 文件,会到 resources->templates 目录下找 index.html

二.使用自定义 xxx.html 作为首页面
1.方法一:通过Controller控制首页
@RestController
public class IndexController {
@RequestMapping("/")
public String hello(){
System.out.println("OK");
return "test";
}
}三.用Controller控制层返回任意html页面
1.在pom.xml文件中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>2.书写Controller层
注解要写@controller而不是@restController,前者用来渲染页面,后者用来返回数据

到此这篇关于SpringBoot项目中访问HTML页面的三种方法的文章就介绍到这了,更多相关SpringBoot访问HTML页面内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
