thymeleaf前端表达式怎么写

thymeleaf前端表达式怎么写,第1张

Thymeleaf 基本表达式

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

${}

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

例如:

protected void doPost()

throws ServletException, IOException {

//Create Servlet context

WebContext ctx = new WebContext(req, resp, thisgetServletContext(), reqgetLocale());

ctxsetVariable("helloword","hello thymeleaf,wellcome!");

//Executing template engine

templateEngineprocess("home", ctx, respgetWriter());

}

模板页面访问变量

<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/homehtml,段落

<p th: text=" #{home welcome}" >This text will not be show! </p>

新建/WEB-INF/templates/homeproperties,homewelcome:

homewelcome=this messages is from homeproperties!

测试结果:

从测试结果可以看出,消息表达式通常用于显示页面静态文本,将静态文本维护在properties文件中也方面维护,做国际化等。

回到顶部

@{}

超链接url表达式。

例如:

<script th:src="@{/resources/js/jquery/jqueryjson-24minjs}"

回到顶部

#maps

工具对象表达式。常用于日期、集合、数组对象的访问。这些工具对象就像是java对象,可以访问对应java对象的方法来进行各种 *** 作。

例如:

<div th:if="${#mapssize(stuReqBeanstudents[__${rowStatindex}__]score) != 0}">

<label>${scorekey}:</label><input type="text" th:value="${scorevalue}"></input>

</div>

<div th:if="${#mapsisEmpty(stuReqBeanstudents[__${rowStatindex}__]score)}">

do something

</div>

其他工具对象表达式还有:

#dates

#calendars

#numbers

#strings

#objects

#bools

#arrays

#lists

#sets

这段时间的一个工作任务是要实现一个本地的管理工具,之前的版本都是使用的javaGUI的界面;但自己对于GUI的使用非常不熟悉,所以就提出使用也买呢的方式实现。由于之前听过说过springboot的大名,所以就决定使用该框架,边学边用。

好在spring官方的文档还是比较多的,稍微看了一下,发现入门比较简单,另外工作任务的也只是需求本地使用,所以需求的功能也不会太苛刻。公司网络限制,只好在家里学好了,再把demo发到公司邮箱。

通过查看文档与比较各个技术难点,初步确定了标题的技术栈,下载了springboot thymeleaf easyui jquery文档就开始搭建demo,目标是实现web项目的基本购价。

以上就是关于thymeleaf前端表达式怎么写全部的内容,包括:thymeleaf前端表达式怎么写、spring boot thymeleaf easyui 怎样抽出公共js、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9335767.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存