有关Springboot整合前端html问题,thymeleaf的使用

在写这篇博客的时候,我也走过很多springboot整合前端的坑,实在是不想让大家再次进入这样的坑,所有下面就是我的一些见解,有错大家请指正。

首先我们要把 静态的资源文件加载在项目下resource文件夹下,当然springboot中不建议使用jsp作为页面展示。springboot默认是使用的thymeleaf模板引擎的

使用

thymeleaf

在pom.xml中添加依赖:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

配置thymeleaf

##thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.mvc.static-path-pattern=/static/**
spring.thymeleaf.cache=false  

这里要声明一下,在springboot中 templates文件下一般是html文件(注:最好名字不要改,因为springboot默认是这个(这里是我没注意看到的,我也忘记怎么表达)),static是一些css,js等东西,一般情况下配置这么多就可以,接着编写controller层代码

@Controller
public class HelloController {

    @GetMapping("/test")
    public String index(){
        return "index";
    }
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值