SpringBoot如何配置和引用国际化资源

2024-10-12 16:38:10

本文主要介绍Spring Boot如何配置国际化资源,以及如何在页面、Java代码引用国际化资源。

工具/原料

Spring Boot 1.5.9.RELEASE

一、配置国际化资源

1、在resource目录下建立目录i18n/messages用于存放国际化资源文件,在messages目录下新建三个文件:messages_en_US.properties、messages_zh_CN.properties、messages.properties。

SpringBoot如何配置和引用国际化资源

3、在Spring boot的配置文件application.properties中添加配置项:spring.messages.basename=i18n/messa爿讥旌护ges/messages注意:最后一个messages一定不能少,最后一个messages表明国际化文件的前缀,如果没有配置则会报错,报错信息类似javax.servlet.jsp.JspTagException: No message found under code 'hello.world' for locale 'zh_CN'

SpringBoot如何配置和引用国际化资源SpringBoot如何配置和引用国际化资源SpringBoot如何配置和引用国际化资源
猜你喜欢