【问题标题】:How to do arithmetic operations on Thymeleaf variable after declare it with default value?使用默认值声明 Thymeleaf 变量后如何对其进行算术运算?
【发布时间】:2018-07-10 03:06:30
【问题描述】:

这里我声明了变量名 someVariable 并分配默认值 10:

<p th:with ="someVariable=10">
        <p th:text ="someVariable=${someVariable}+${someVariable}"> </p>
        <p th:text ="${someVariable}"> </p>
</p>

之后我正在更改变量的值,但出现错误。

在 Thymeleaf 中声明变量后如何更改其值?

【问题讨论】:

    标签: java templates spring-boot thymeleaf


    【解决方案1】:

    像这样:

    <p th:with="someVariable=10">
        <p th:with="someVariable=${someVariable + someVariable}">
            <span th:text="${someVariable}"></span>
        </p>
    </p>
    

    【讨论】:

    • 我得到了输出 20,因为我在内部 P 选项卡中打印了 someVariable 的值,但是当我再次打印 someVariable 的值时,我得到了结果 10
    • 因为超出了范围!
    猜你喜欢
    • 2021-11-27
    • 2014-05-05
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多