spring boot(三) thymeleaf模板引擎

1、添加起步依赖

<!-- thymeleaf模块集成 -->
		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

这里默认的版本是2.1.1,如果需要改成最新版本

在github中最新版本

 

添加下面配置即可

<properties>
		<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
	</properties>

2、thymeleaf自动配置

源码路径org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration

在源码中可以看见默认路径前缀classpath:/templates、后缀.html

3、界面跳转

接口

@RequestMapping("/hello")
	public String helloPage(){
		return "hello";
	}

界面,一定要建在templates路径下

成功跳转

3、thymeleaf使用

thymeleaf官网

3.1、导入thymeleaf命名空间

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

3.2、将我们前面的hello接口调整如下

@RequestMapping("/hello")
	public String helloPage(Map<String, Object> map){
		map.put("hello", "你好");
		return "hello";
	}

3.3、在界面获取hello属性

<div th:text="${hello}"></div>

看见你好已经返回到界面上了!

更多thymeleaf语法可以下载官方提供的pdf文档。也可以在我的网盘下载 :usethymeleaf  提取码 zc7h

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值