如需了解thymeleaf以及thymeleaf整合spring,请参考《Thymeleaf模板引擎使用》、《Thymeleaf 集成spring

${}

变量表达式(美元表达式,哈哈),用于访问容器上下文环境中的变量,功能同jstl中${}。

例如:

protected void doPost(HttpServletRequest req, HttpServletResponse resp) 

throws ServletException, IOException {

...

//Create Servlet context

WebContext ctx = new WebContext(req, resp, this.getServletContext(), req.getLocale());

ctx.setVariable("helloword","hello thymeleaf,wellcome!");

//Executing template engine

templateEngine.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

thymeleaf 基本表达式的更多相关文章

  1. 初步认识thymeleaf:简单表达式和标签(二)

    1.th:each:循环,<tr th:each="user,userStat:${users}">,userStat是状态变量,有 index,count,size, ...

  2. 初步认识thymeleaf:简单表达式和标签(一)

    初步认识Thymeleaf:简单表达式和标签.(一)   本文只适用于不会Java对HTML语言有基础的程序员们,是浏览了各大博客后收集整理,重新编辑的一篇文章,希望能对大家有所帮助.最后本文如果有哪 ...

  3. Thymeleaf 标准表达式语法

    变量表达式${ } 在控制器中往页面传递几个变量: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 @Controller public class IndexController ...

  4. (二)Thymeleaf标准表达式之——简单表达式

    2. 标准表达式(Standard Expression Syntax) 标准表达式包含以下几个方面: 简单表达式: 变量表达式: ${...} 选择变量表达式: *{...} 消息表达式: #{.. ...

  5. thymeleaf中th:attr用法以及相关的thymeleaf基本表达式

    额,有人写的很好,我直接搬了 thymeleaf中th:attr用法 1.写死的单个属性值添加 th:attr="class=btn" 2.写死的多个属性值添加 th:attr=& ...

  6. Thymeleaf 页面表达式基础

    转自:http://www.cnblogs.com/vinphy/p/4674247.html#undefined (一)Thymeleaf 是个什么?      简单说, Thymeleaf 是一个 ...

  7. Thymeleaf标准表达式

    Thymeleaf的官网为: http://www.thymeleaf.org/ 一.变量表达式${-} 使用${-}括起来的表达式,称为变量表达式.该表达式的内容会显示在HTML标签体文本处. 该表 ...

  8. thymeleaf条件表达式

    条件表达式形式:condition, then and else <tr th:class="${row.even}? 'even' : 'odd'"> ... < ...

  9. Thymeleaf模板表达式

    日期格式.组件提取等. ${#dates.format(date)}${#dates.arrayFormat(datesArray)}${#dates.listFormat(datesList)}${ ...

随机推荐

  1. Linux系统安装时分区的选择(推荐)

    Linux系统安装时分区的选择(推荐)  出处:http://www.cnblogs.com/gylei/archive/2011/12/04/2275987.html 前言: 以前初识Linux时, ...

  2. 解决Odoo出现的Unable to send email, please configure the sender's email address or alias.

    这是由于当前登录用户的邮件地址信息缺失造成的,需要设置其邮件地址. 方法:使用创建该用户的管理员帐号登录系统,开启技术特性,在需要设置邮箱地址的用户界面点击相关的业务伙伴标签链接,如图所示:

  3. Jquery获取select 控件的change事件时选中的值

    HTML代码如下: <div class="col-sm-9 col-xs-12"> <select id="groupid" class=& ...

  4. tableView设置首尾

    [self.tableView setTableHeaderView:view]; [self.tableView setTableFooterView:view];

  5. webstorm配置scss自动编译路径

    webstorm支持sass的同步编译,也就是即写即编译,并且可以指定编译后的css的目录. 本文使用的webstorm为8.0版本 scss安装:http://www.w3cplus.com/sas ...

  6. Swift - as、as!、as?三种类型转换操作使用一览

    as.as!.as? 这三种类型转换操作符的异同,以及各自的使用场景.   1,as使用场合 (1)从派生类转换为基类,向上转型(upcasts) 1 2 3 4 class Animal {} cl ...

  7. DB2 SQL Mixed data in character strings

    Mixed character data and graphic data are always allowed for Unicode, but for EBCDIC and ASCII, the ...

  8. NYOJ题目114某种序列

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAscAAAHuCAIAAAD83zYaAAAgAElEQVR4nO3dP1LjygIv4LcJ5yyE2A

  9. java的基本结构

  10. python字符串中插入变量