Thymeleaf 字符串模板
我无法弄清楚我在这里做错了什么 -
@Test
void should_fill_a_string_template() {
String template = "Hello ${name}";
StringTemplateResolver resolver = new StringTemplateResolver();
Context context = new Context();
context.setVariable("name","Test");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(resolver);
String result = templateEngine.process(template, context);
Assertions.assertEquals("Hello Test",result);
}
我只想在一个普通的旧 java 项目中使用 Thymeleaf 模板处理器,而无需其他依赖项。我需要传入一个字符串(不是要解析的文件)并让模板填充提供的值。
我看到默认行为 此处 表示 StringTemplateResolver 应该只解析作为模板本身传入的字符串,而不是对 模板。
我在这里缺少什么?
I'm having trouble working out what I'm doing wrong here -
@Test
void should_fill_a_string_template() {
String template = "Hello ${name}";
StringTemplateResolver resolver = new StringTemplateResolver();
Context context = new Context();
context.setVariable("name","Test");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(resolver);
String result = templateEngine.process(template, context);
Assertions.assertEquals("Hello Test",result);
}
I just want to use the Thymeleaf template processor in a plain old java project without other dependencies. I need to pass in a String (not a file to be resolved) and have the template filled with the values provided.
I see the default behavior here indicates that the StringTemplateResolver should just resolve the string passed in as the template itself and not a reference to the template.
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论