一.将 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页面内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论