关于springboot访问html页面

spring boot访问页面需要thymeleaf模板依赖

在pom文件中引入

<dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

1.直接访问页面

你只需要创建一个新的html文件 放到resource目录下的static目录下即可

然后直接localhost:8888/*.html(*代指的是你的页面名称)

2.通过控制层访问页面

此时你的页面应该放的位置templates目录下(同理:如果你没有该目录,你可以自行创建即可)

在controller文件中

@Controller

@RequestMapping("demo")

public class Demo {

             @RequestMapping("/demo")

             public String demo(){

             return "demo3";

} }

3.yml配置(可选)

spring:
    # thyleaf模板
    thymeleaf:
      prefix: classpath:/templates/
      suffix: html
      mode: HTML5
      encoding: UTF-8
      content-type: text/html
      cache: false

访问:localhost:8080/demo/demo即可

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值