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">

 

全部评论

相关推荐

高斯林的信徒:武大简历挂?我勒个骚岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务