【发布时间】:2023-04-06 00:06:01
【问题描述】:
我正在为我的 Spring Boot 应用程序使用 thymeleaf 模板。在主页下方,
<div th:replace="content :: content"></div>
和内部内容片段,
<div th:fragment="content">
<h4 th:if="${param.val== 'abc'}">SOME-TEXT</h4> // not working
<h4 th:if="${param.val== 'abc'}" th:text="${param.val}"></h4> // not working
<h4 th:text="${param.val}"></h4> // working and value is abc
<h4 th:unless="${param.val== 'abc'}" th:text="${param.val}"></h4> // working - value in html text is abc
<h4 th:unless="${param.val== 'abc'}">SOME-TEXT</h4> // Working, value is SOME-TEXT
</div>
URL: domain/?val=abc
如果 param.val == 'abc',我想在 html 中显示:SOME-TEXT。 值“abc”进入 th:text。但是在里面:如果失败了。
似乎在 param.val 中添加了一些隐藏的额外字符串? 有什么建议吗?
【问题讨论】:
-
th:if 只负责决定是否包含那个 。如果您仍然希望将“SOME-TEXT”替换为“abc”,则还需要使用 th:text:
<h4 th:if="${param.val== 'abc'}" th:text="${param.val}"> -
是的。但有点 th;如果使用 param.val 检查不起作用。
--> 不工作。但是
--> 工作
-
另外, --> 工作.似乎在 param.val 中添加了一些额外的字符?
标签: spring-boot thymeleaf