【发布时间】:2020-02-24 19:25:02
【问题描述】:
在我的应用程序中,我需要使用“硬连线”html 模板,我将通过将它们添加到 resources/templates 和“动态”文本模板来烘焙它们,我想在运行时将它们存储在 Strings 中。
我的代码如下所示:
@Autowired
SpringTemplateEngine templateEngine;
templateEngine.addTemplateResolver(new DynamicTemplateResolver());
Context context = new Context();
context.setVariable("foo1", ... );
templateEngine.process("eitherStaticOrDynamic", context, output);
问题在于实现ITemplateResolver 的DynamicTemplateResolver。我尝试使用Process string templates with thymeleaf 3 提供的示例,但它们似乎不再适用于当前版本的 Spring。
如何从 Strings 解析模板?我使用 Spring Boot 2.2
【问题讨论】:
标签: spring spring-boot templates thymeleaf