将html注入百里香模板

Rus*_*dov 2 java spring thymeleaf spring-boot

我在数据库中有百里香模板,

首先,我检索模板并对其进行处理:

String processedTemplate = templateEngine.process(databaseTemplate, context);
Run Code Online (Sandbox Code Playgroud)

所以现在processedTemplate包含htmlString

然后,我检索另一个模板并进行基本相同的操作,但我还想将先前的模板注入其中,因此Java代码应如下所示:

Context context = new Context(Locale.ENGLISH);
context.setVariable("htmlToInject", processedTemplated);
String result = templateEngine.process(mainTemplate, context);
Run Code Online (Sandbox Code Playgroud)

那么,我应该放入什么内容mainTemplate才能将另一个html Context注入其中呢?

我看到了这样的东西:

String processedTemplate = templateEngine.process(databaseTemplate, context);
Run Code Online (Sandbox Code Playgroud)

但是它适用于文件中的模板,但不适用于它们位于数据库中的模板。

hol*_*s83 5

听起来您想插入文本而不使用HTML转义,您可以使用以下命令th:utext

<div th:utext="${htmlToInject}"></div>
Run Code Online (Sandbox Code Playgroud)

内联

[(${htmlToInject})]
Run Code Online (Sandbox Code Playgroud)