Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在thymeleaf中设置变量名的值_Java_Html_Spring_Jsp_Thymeleaf - Fatal编程技术网

Java 在thymeleaf中设置变量名的值

Java 在thymeleaf中设置变量名的值,java,html,spring,jsp,thymeleaf,Java,Html,Spring,Jsp,Thymeleaf,我不熟悉Thymeleaf,不熟悉如何将我的网页从JSP转换为Thymeleaf。我有一个这样的支撑标签: <c:set var="someVariable" value="${someValue}"/> 该变量可以在JSP中的任何位置使用。在Thymeleaf中有这样的替代方案吗?您可以使用 声明一个带有th:with属性的HTML元素。比如说 <div th:with="someVariable=${someValue}"> 文件说明 当处理th:with

我不熟悉Thymeleaf,不熟悉如何将我的网页从JSP转换为Thymeleaf。我有一个这样的支撑标签:

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

该变量可以在JSP中的任何位置使用。在Thymeleaf中有这样的替代方案吗?

您可以使用

声明一个带有
th:with
属性的HTML元素。比如说

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

文件说明

当处理
th:with
时,该
[someVariable]
变量被创建为 局部变量,并添加到来自上下文的变量映射中, 因此,它与任何其他变量一样可用于评估 从一开始就在上下文中声明,,但仅在范围内 包含标签的属性。


请注意,如果要分配多个变量,请用逗号分隔:

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

参见第三个示例:

  • th:with=“varName=${'str'}声明

  • 在src
    th:src=“@{${varName}}”中使用ref

  • 更详细地说:

  •