Springboot访问html页面的教程详解

2022-10-18,,,,

这篇文章主要介绍了Springboot访问html页面的教程,本文图文并茂给大家介绍的非常详细,需要的朋友可以参考下

1. 在原有的项目resouces目录下创建static包,并在static下创建pages,然后在pages包下hello.html.

这时你会发现hello.html并没有在static中,它跑哪去了呢?打开src下的webapp,发现有一个hello.htm,删除web.xml,并将hello.html用鼠标左键移到static目录下;

hello.html代码:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"/> 
<title>Insert title here</title> 
</head> 
<body> 
 <h1>springboot访问第一个html页面</h1> 
</body> 
</html> 

1.1. 创建springboot配置文件application.roperties

在创建resouces目录下创建application.properties,创建完成后会出现一个绿叶图标

打开application.properties,添加如下配置:

spring.mvc.view.prefix=/pages/ 
spring.mvc.view.suffix=.html 

1.2.修改SpringBootController中的代码

改成

1.3.测试

启动Appliction中的main方法(springboot应用的入口)

打开浏览器访问http://localhost:8080/hello

效果:

总结

以上所述是小编给大家介绍的Springboot访问html页面的教程详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对北冥有鱼网站的支持!

您可能感兴趣的文章:

  • Springboot下swagger-ui.html访问不到的解决方案
  • springboot访问template下的html页面的实现配置
  • SpringBoot使用Thymeleaf模板引擎访问静态html的过程
  • Springboot访问html页面步骤解析
  • Springboot访问templates html页面过程详解
  • springboot如何使用thymeleaf模板访问html页面
  • SpringBoot项目中如何访问HTML页面

《Springboot访问html页面的教程详解.doc》

下载本文的Word格式文档,以方便收藏与打印。