Springboot返回html
注:Springboot的版本2.1.3.RELEASE
List-1 application.properties文件
1 | server.port=8080 |
整体结构如下图1所示,html要放在static下,不是templates下

图1
List-2 HelloController的内容如下
1 | import lombok.extern.slf4j.Slf4j; |
List-3 启动springboot,之后在浏览器中输入
1 | #返回index.html的内容 |
网上很多关于模板的(Thymeleaf 、FreeMarker 等),但是我不需要,我只需要纯的html。
index.html是springboot的默认welcome page。
Reference
- https://www.jianshu.com/p/eb4c0fc2dfc4
- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content
- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-welcome-page
(adsbygoogle = window.adsbygoogle || []).push({});