thymeleaf入门

HTML标签

<head>  <!-- meta 会报错-->
    <meta charset="UTF-8" />
    <link rel="stylesheet" th:href="${myName}+'/platform/common/s/1.1/global/global.css'"/>
    <title>Title</title>
</head>

HTML标签中

<span th:text="'Welcome to our application, ' + ${myName} + '!'" />
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<body   th:text="'Something went wrong: ' + ${status} + ' '+${error}" >
</body>

</html>

JavaScript 中

<script th:inline="javascript">
    var myVar = [[${myName}]];
    console.log(myVar);
	const baseUrl = '[(${baseUrl})]';
        const picUrl = '[(${picUrl})]';
</script>

使用前提

  1. 引入依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
  1. html 标签增加属性
xmlns:th="http://www.thymeleaf.org"

帮助文档

https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html https://www.kancloud.cn/cxr17618/springboot/428898 https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html

转载于:https://my.oschina.net/huangweiindex/blog/2964260

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值