Spring boot 国际化I18n 基本使用,如果有特殊需 基本信息1、Locale 类里面有各种语言定义static public final Locale CHINESE createConstant(zh, );static public final Locale SIMPLIFIED_CHINESE createConstant(zh, CN);spring boot配置使用1、在 application.yml 配置messages信息spring:messages:basename: messagesencoding: UTF-8 # 文件编码避免中文乱码cache-duration: 5m # 缓存时间可选如 5m、1hfallback-to-system-locale: true # 如果找不到当前语言回退到系统默认语言可选2、配置resource bundle文件新建一个文件新建下面的文件messages.propertiesmessages_en_US.propertiesmessages_zh_CN.properties文件内容1、获取国际化信息1、ControllerRestControllerRequestMapping(ssdemo)public class SpringDemoController {Autowiredprivate MessageSource messageSource;//localhost:19697/ssdemo/i18nGetMapping(i18n)ResponseBodypublic String getI18N(Locale locale){//locale Locale.forLanguageTag(en-US);String msg messageSource.getMessage(myfirstMsg,null,locale);return msg;}}2)、代码org.springframework.context.support.AbstractMessageSource.getMessage();