thymeleaf

一.HTML模板

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Index Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <p th:text="${message}">Welcome to BeiJing!</p>
</body>
</html>

二.thymeleaf标准表达式

${...} 变量表达式
*{...} 选择变量表达式
#{...} 消息表达式
@{...} 链接url表达式

三.thymeleaf属性使用

1.th:text  th:utext

<!-- th:text 为Thymeleaf属性,用于展示纯文本,会对特殊字符进行转义-->
<!-- 经过thymeleaf解析后,会将原来的内容进行替换 -->
<div th:text="hello">world</div>
    
<!-- th:utext    文本替换,不转义特殊字符 -->
<div th:utext="hello" >Hi</div>

 th:text和th:utext的异同:

相同:

        1.都可以对变量或表达式进行求值

    <div id="thymeleaf-id"></div>

        2.用“ + ”可进行文本连接

不同:

        当获取从后段传来的参数带有html标签时 th:text不会进行解析 th:utext进行解析

2.th:id

替换id属性

<div id="id1" th:id="thymeleaf-id"></div>

页面解析后:

    <div id="thymeleaf-id"></div>

3. th:value

替换value属性

<input type="text" value="input" th:value="thymeleaf_value"/>

4.th:object

{}选择表达式选取值 若父标签没有选择对象,字标签使用*{}选择表达式或${}变量表达式效果是一样的, 同时父标签选择了对象,字标签仍可用${}变量表达式取值

<div th:object="${user}">
         第一:<span th:text="*{username}"></span>
     </div>
     <div>
         第二:<span th:text="*{user.username}"></span>
     </div>
     <div th:object="${user}">
         第三:<span th:text="${user.username}"></span>
     </div>

解析后:

        第一:张三

        第二:张三

        第三:张三th:with

5.th:with

局部变量赋值运算

<span th:with="a = 'hello world'" th:text="${a}"></span>

四.传参方式

thymeleaf采用form表单向后台提交数据
<form class="logonmain" action="users/login" method="POST">
    <input name='sex'/>
    <input type='sunmit'> //提交表单
</form>

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值