Java 弹簧靴&x2B;Thymeleaf,连接新格式化程序

Java 弹簧靴&x2B;Thymeleaf,连接新格式化程序,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我正在弹簧靴上构建应用程序。此时,我决定使用Thymeleaf来呈现这个应用程序中的一些消息。应用程序使用Thymeleaf配置来呈现作为字符串提供的模板 这是Thymeleaf配置: @Bean public SpringTemplateEngine templateEngine() { final SpringTemplateEngine engine = new SpringTemplateEngine(); engine.setDialect(templateDialec

我正在弹簧靴上构建应用程序。此时,我决定使用Thymeleaf来呈现这个应用程序中的一些消息。应用程序使用Thymeleaf配置来呈现作为字符串提供的模板

这是Thymeleaf配置:

@Bean
public SpringTemplateEngine templateEngine() {
    final SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setDialect(templateDialect());
    engine.setTemplateResolver(templateResolver());
    engine.setEnableSpringELCompiler(true);

    return engine;
}

@Bean
public StringTemplateResolver templateResolver() {
    final StringTemplateResolver templateResolver = new StringTemplateResolver();
    templateResolver.setTemplateMode(TemplateMode.TEXT);

    return templateResolver;
}

@Bean
public SpringStandardDialect templateDialect() {
    final SpringStandardDialect dialect = new SpringStandardDialect();
    dialect.setEnableSpringELCompiler(true);

    return dialect;
}
这是我用于渲染的代码:

final Context context = new Context();

    context.setVariables(/*provide map with "variable" in it*/);

    return engine.process("[[${variable}]]", context);

当我试图处理列表对象时,问题就出现了。我想为列表类型添加格式化程序,以便以正确的方式呈现它。我已经尝试通过重写方法:AddFormatters使用WebMVCConfiguer类来实现这一点,但迄今为止没有成功。

为什么要使用Thymeleaf实现这一点?您还可以使用
MessageSource
中的常规消息进行替换。MessageSource如何能够在单个上下文中处理包含多个变量的模板,包括模板内部的方法调用?百里香提供了所有这些。我不确定MessageSource。它可以支持您想要的任意多个变量。。。方法调用可能是一个问题,但您应该首先在消息模板中进行方法调用,还是只处理模型?