springboot后台服务搭建(二 整合thymeleaf)

总览:https://blog.csdn.net/qq_22037575/article/details/86687765

本文概要:springboot2.x 整合 thymeleaf

码云:https://gitee.com/RichterGit/csdn/tree/master/springboot-radmin/002/

目录

1.导入依赖包

2.全局配置

3.访问

4.页面使用 thymeleaf


1.导入依赖包

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

 2.全局配置

因为 pom文件中导入了 web依赖,基于springmvc,这里可以在全局配置文件 application.properties中配置访问页面的前后缀,在idea中前缀 prefix默认 classpath:/templates/,templates文件夹是新建项目时默认生成的,主要用来存放与页面相关的html文件,后缀 suffix默认是空字符串(也就是什么都没有),我这里因为采用 thymeleaf作页面的渲染模板,页面后缀基本是html,所以配置后缀 suffix为 ".html"

spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html

 3.访问

 因为全局配置文件application.properties中配置了页面的后缀 suffix为.html“”,所以 ModelAndView设置页面时省略了“.html”,所以原本的 mav.setViewName("/login.html") 变成 mav.setViewName("/login")

 

 4.页面使用 thymeleaf

 在 html页面上使用 thymeleaf之前,需要在页面的标签<html> 中声明标签 <th>,这里使用 <th:if>标签做测试

<html xmlns:th="http://www.thymeleaf.org">

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值