thymeleaf 基本表达式
来源:互联网 发布:iphone视频编辑软件 编辑:程序博客网 时间:2024/06/10 00:50
${}
变量表达式(美元表达式,哈哈),用于访问容器上下文环境中的变量,功能同jstl中${}。
例如:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {...//Create Servlet contextWebContext ctx = new WebContext(req, resp, this.getServletContext(), req.getLocale());ctx.setVariable("helloword","hello thymeleaf,wellcome!");//Executing template enginetemplateEngine.process("home", ctx, resp.getWriter());}
模板页面访问变量
<p><span th:text="${helloword}"></span></p>
回到顶部
*{}
选择表达式(星号表达式)。选择表达式与变量表达式有一个重要的区别:选择表达式计算的是选定的对象,而不是整个环境变量映射。也就是:只要是没有选择的对象,选择表达式与变量表达式的语法是完全一样的。那什么是选择的对象呢?是一个:th:object对象属性绑定的对象。
例如:
<div th: obj ect=" ${session. user}" ><p>Name: <span th: text=" *{firstName}" >Sebastian</span>. </p><p>Surname: <span th: text=" *{lastName}" >Pepper</span>. </p><p>Nationality: <span th: text=" *{nationality}" >Saturn</span>. </p></div>
上例中,选择表达式选择的是th:object对象属性绑定的session. user对象中的属性。
回到顶部
#{}
消息表达式(井号表达式,资源表达式)。通常与th:text属性一起使用,指明声明了th:text的标签的文本是#{}中的key所对应的value,而标签内的文本将不会显示。
例如:
新建/WEB-INF/templates/home.html,段落
<p th: text=" #{home. welcome}" >This text will not be show! </p>
新建/WEB-INF/templates/home.properties,home.welcome:
home.welcome=this messages is from home.properties!
测试结果:
从测试结果可以看出,消息表达式通常用于显示页面静态文本,将静态文本维护在properties文件中也方面维护,做国际化等。
回到顶部
@{}
超链接url表达式。
例如:
<script th:src="@{/resources/js/jquery/jquery.json-2.4.min.js}"
回到顶部
#maps
工具对象表达式。常用于日期、集合、数组对象的访问。这些工具对象就像是java对象,可以访问对应java对象的方法来进行各种操作。
例如:
<div th:if="${#maps.size(stuReqBean.students[__${rowStat.index}__].score) != 0}"><label>${score.key}:</label><input type="text" th:value="${score.value}"></input></div><div th:if="${#maps.isEmpty(stuReqBean.students[__${rowStat.index}__].score)}">...do something...</div>
其他工具对象表达式还有:
#dates#calendars#numbers #strings#objects#bools#arrays#lists#sets
更多详细表达式请访问:http://www.thymeleaf.org
阅读全文
0 0
- thymeleaf 基本表达式
- thymeleaf条件表达式
- Thymeleaf模板表达式
- Thymeleaf变量表达式
- Thymeleaf消息表达式
- Thymeleaf选择变量表达式
- Thymeleaf URL表达式
- Thymeleaf 标准表达式语法
- Thymeleaf标准表达式语法
- Thymeleaf模板引擎基本用法
- Thymeleaf模板引擎基本语法
- Thymeleaf条件表达式和默认表达式
- Thymeleaf的表达式语言-原标题:Expression Language in Thymeleaf
- Thymeleaf教程 (四) Thymeleaf标准表达式语法(上)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- Thymeleaf教程 (四) Thymeleaf标准表达式语法(上)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- using thymeleaf之二简单表达式
- 下载和使用网络上的XYZ格式栅格切片
- Java工程师跳槽的一些想法
- 【Java】简历对应技术整理-包含JVM
- 面试过阿里等互联网大公司,我知道了这些套路 | 掘金技术征文
- 10.20 课件题目练习 贪心+MST+最短路+划分DP
- thymeleaf 基本表达式
- 2017中国开源年会(COSCon'17) 正式开启-逐浪字库倾力支持
- Java面试题(131-135)
- 【手把手】JavaWeb 入门级项目实战
- Java网络编程简单的UDP
- No resource identifier found for attribute 'textAlignment' in package 'android',
- 守护进程创建——setsid()
- token签名验证
- Android ijkplayer的使用解析