java 如何在百里香叶中包含 message.properties
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30106659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include message.properties with thymeleaf
提问by osagie
I am using spring boot with thymeleaf. This is my project structure:
我正在使用带有百里香叶的弹簧靴。这是我的项目结构:
And this is my App start class:
这是我的应用程序启动类:
@EnableAutoConfiguration
@Configuration
@ComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
}
}
I have this on my home.leaf.html: <p th:text = "#{username}"></p>
我的 home.leaf.html 上有这个: <p th:text = "#{username}"></p>
But when I run this application this is what I get: ??username_en_US??
但是当我运行这个应用程序时,我得到的是:??username_en_US??
I have tried various things on how to resolve this configuration issue. Please, can anyone help?
我已经尝试了各种有关如何解决此配置问题的方法。拜托,有人可以帮忙吗?
回答by Faraj Farook
Refer the official documentation for spring boot
spring boot参考官方文档
It says
它说
Static resources can be moved to
/public
(or/static
or/resources
or/META-INF/resources
) in the classpath root. Same formessages.properties
(Spring Boot detects this automatically in the root of the classpath).
静态资源可以移动到
/public
(或/static
或/resources
或/META-INF/resources
)类路径根目录中。相同messages.properties
(Spring Boot 在类路径的根目录中自动检测到这一点)。
So you should create ur internationalization file as messages.properties
and place in the root classpath.
所以你应该创建你的国际化文件messages.properties
并将其放在根类路径中。
Or you can also edit the default location to a more proper location by adding this entry in the application.properties
file
或者您也可以通过在application.properties
文件中添加此条目来将默认位置编辑为更合适的位置
#messages
spring.messages.basename=locale/messages
so you can store your files in the locale folder inside resources folder, with the name messages.properties
or in any specific language.
因此您可以使用名称messages.properties
或任何特定语言将文件存储在资源文件夹内的语言环境文件夹中。