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界面内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
SpringCloud使用集中配置组件Config规避信息泄露
项目应用中,数据库连接信息、Access-key、Secret-key等由于其及其敏感和特殊性,一旦泄露出去就很可能会使得应用遭到黑客攻击,例如数据库账号密码泄露可能导致“拖库”,甚至数据丢失。此等事件偶有发生,那么,在分布式微服务项目中,怎么避免这种情况呢2022-07-07
Spring Cloud使用Feign进行远程调用的操作指南
本文介绍了Feign作为声明式HTTP客户端在SpringCloud中的使用,从简介、对比RestTemplate的问题、使用步骤,到日志配置、性能优化和实际应用进行了详细讲解,包括如何通过Feign简化接口调用,以及解决启动时找不到FeignClient的问题,需要的朋友可以参考下2025-02-02
spring boot如何通过自定义注解和AOP拦截指定的请求
这篇文章主要介绍了spring boot通过自定义注解和AOP拦截指定的请求,本文主要通过切面类和自定注解的方式,拦截指定的接口(代码中已经作了详细的说明),需要的朋友可以参考下2024-06-06


最新评论