SpringBoot 返回Html界面的操作代码
SpringBoot 返回Html界面
1.添加依赖spring-boot-starter-web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
2.创建Html界面
在Resources/static 文件夹下面建立对应的html,比如我这边建立一个pages文件夹,然后再建立一个WelinkLogin的html界面。
3.完成
输入地址:运行输入地址http://localhost:8080/pages/welinklogin.html
springboot配置html页面
最近写了一下springboot , 碰到了一个配置 html 的问题 , 专门 记录一下
首先 说明 , 有两种 访问html 的方式
1.通过后台跳转到 html 页面
现在比较流行的开发模式就是 前后端分离, 在分离的情况下 , 就无法直接访问到 html , 需要通过 后端来跳转
(1.) 添加maven
<!-- 动态页面 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2.) 配置 application.yml
spring: thymeleaf: prefix: classpath: /templates # 访问template下的html文件需要配置模板,映射 cache: false # 开发时关闭缓存,不然没法看到实时页面
(3) controller
@Controller @RequestMapping("/delete/") public class deleteController { @RequestMapping("wrong") public String index() { return "wrong"; } }
注意 :
访问方法跳转页面 方法请求加/ 返回到某一个页面不用.后缀名 并且类上的注解改为@controller 不是@rest Controller
通过访问 localhost:8080/delete/wrong 就可以访问到 templates下的wrong.html页面.
2.直接访问 html 页面
配置applicaiton.yml
不用通过方法访问页面 spring: resources: static-locations: classpath:/static/, classpath:/templates/
就可以通过 localhost:8080/wrong.html 访问
到此这篇关于SpringBoot 返回Html界面的文章就介绍到这了,更多相关SpringBoot Html界面内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
java.sql.SQLException问题解决以及注意事项
这篇文章主要给大家介绍了关于java.sql.SQLException问题解决以及注意事项的相关资料,这个问题其实很好解决,文中通过图文将解决的办法介绍的很详细,需要的朋友可以参考下2023-07-07SpringBoot mybatis 实现多级树形菜单的示例代码
这篇文章主要介绍了SpringBoot mybatis 实现多级树形菜单的示例代码,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2021-05-05模仿J2EE的session机制的App后端会话信息管理实例
下面小编就为大家分享一篇模仿J2EE的session机制的App后端会话信息管理实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2017-11-11
最新评论