Spring,Thymeleaf和本地化字符串

 mobiledu2502870957 发布于 2023-02-11 14:43

我是使用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;
}

在login.html内:

    

Welcome to our site!

内部messages_en.properties:

    messages.hello=Apparently messages work

我的项目结构:

结构体

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

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有