【发布时间】:2014-05-16 19:31:51
【问题描述】:
我希望能够将具有 Thymeleaf 属性的 HTML 作为字符串存储在数据库中。我已经能够存储没有 Thymeleaf 属性的 HTML:
控制器类中的方法
// this method would actually get String from database first
@ModelAttribute("someCode")
public String populateSomeCode() {
return "This is <h1>some code</h1>";
}
index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
...
<body>
<div th:utext="${someCode}">HTML will go here</div>
</body>
</html>
这将产生显示“这是一些代码”的 H1 的预期结果。
我想知道是否可以在字符串中包含 Thymeleaf 属性,然后处理这些属性。如果我将字符串更改为:
"This is <h1 th:text=\"'another String'\">some code</h1>"
我希望结果是一个 H1 说“这是另一个字符串”,但目前它仍然会说“这是一些代码”。有没有办法做到这一点?
【问题讨论】:
标签: spring-mvc template-engine thymeleaf