Java Thymeleaf设置没有WEB的消息资源
在这个场景中,没有web配置,没有springmvc,没有springboot等等。仅仅是纯应用程序,我想使用Thymeleaf传输静态html资源,并获取字符串中的内容 但是,在这种情况下,如何为thymeleaf设置国际消息?所以我可以在静态html文件中使用Java Thymeleaf设置没有WEB的消息资源,java,internationalization,thymeleaf,Java,Internationalization,Thymeleaf,在这个场景中,没有web配置,没有springmvc,没有springboot等等。仅仅是纯应用程序,我想使用Thymeleaf传输静态html资源,并获取字符串中的内容 但是,在这种情况下,如何为thymeleaf设置国际消息?所以我可以在静态html文件中使用 <h1 th:text="#{messageA}">AAAAA</h1> AAAAA 您只需要定义一个消息源。例如,在spring配置中,我有一个主要方法: @Configuration @Component
<h1 th:text="#{messageA}">AAAAA</h1>
AAAAA
您只需要定义一个消息源。例如,在spring配置中,我有一个主要方法:
@Configuration
@ComponentScan(basePackages = {"spring.cli.config"})
public class Main {
public static void main(String... args) throws Exception {
ConfigurableApplicationContext spring = new SpringApplicationBuilder(Main.class)
.web(NONE)
.profiles("default")
.run(args);
TemplateEngine engine = (TemplateEngine) spring.getBean("engine");
Context context = new Context();
System.out.println(engine.process("template", context));
}
}
和一个配置文件(在@ComponentScan(basePackages={“spring.cli.config”})
中扫描):
我的项目中有一个文件src/main/resources/messages.properties
# messages.properties
messageA=Hello I am message A
在html中:
<h1 th:text="#{messageA}">AAAAA</h1>
AAAAA
决心:
<div>Hello I am message A</div>
你好,我是一条消息
<div>Hello I am message A</div>