在百里香叶中设置变量名的值 [英] setting up a value for a variable name in thymeleaf

查看:103
本文介绍了在百里香叶中设置变量名的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的百里香,并且正在将ma网页从jsp转换为百里香。我有一个像这样的标签标签

 < c:set var =someVariablevalue =$ {someValue}/ > 

这个变量可以在jsp的任何地方使用。有没有这样的替代品在thymeleaf?

解决方案

您可以使用局部变量

声明一个HTML元素一个 th:带属性。例如

 < div th:with =someVariable = $ {someValue}> 

文档状态


th:处理时, [someVariable] 变量被创建为
局部变量,并添加到来自上下文的变量映射
中,以便它可用于评估和上下文中从头开始声明的任何其他变量
一样,但仅限于边界$


包含标签的b $ b。

I am new to thymeleaf and am converting ma web page from jsp to thymeleaf. I have a strut tag like this

<c:set var="someVariable" value="${someValue}"/>

which that the variable can be used anywhere in jsp. Is there any such alternatives for this in thymeleaf?

解决方案

You can use local variables.

Declare an HTML element with a th:with attribute. For example

<div th:with="someVariable=${someValue}">

The documentation states

When th:with is processed, that [someVariable] variable is created as a local variable and added to the variables map coming from the context, so that it is as available for evaluation as any other variables declared in the context from the beginning, but only within the bounds of the containing tag.

这篇关于在百里香叶中设置变量名的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆