小编Chr*_*nis的帖子

Spring,Thymeleaf和本地化字符串

我是使用Spring和Thymeleaf的新手,我无法弄清楚我的本地化.properties文件的位置.我有这个豆子:

@Bean
public MessageSource messageSource() {

    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("classpath:messages/messages", "classpath:messages/validation");
    // if true, the key of the message will be displayed if the key is not
    // found, instead of throwing a NoSuchMessageException
    messageSource.setUseCodeAsDefaultMessage(false);
    messageSource.setDefaultEncoding("UTF-8");
    // # -1 : never reload, 0 always reload
    messageSource.setCacheSeconds(0);

    return messageSource;
}
Run Code Online (Sandbox Code Playgroud)

在login.html内:

    <p th:text="#{messages.hello}">Welcome to our site!</p>
Run Code Online (Sandbox Code Playgroud)

内部messages_en.properties:

    messages.hello=Apparently messages work
Run Code Online (Sandbox Code Playgroud)

我的项目结构:

结构体

我已经尝试在WEB-INF中创建一个名为messages的文件夹,但显然我没有得到正确的答案.有任何想法吗?

编辑:使用与消息相关的代码更新了问题.

netbeans spring-mvc thymeleaf

6
推荐指数
1
解决办法
7147
查看次数

标签 统计

netbeans ×1

spring-mvc ×1

thymeleaf ×1