zoukankan      html  css  js  c++  java
  • springboot-国际化

    https://blog.csdn.net/liujun03/article/details/82775634

    一、国际化基本原理
    在Spring程序中,国际化主要是通过ResourceBundleMessageSource这个类来实现的,那么下面我们分析一下Spring Boot是如何实现国际化支持的。
    Spring Boot通过MessageSourceAutoConfiguration是为我们自动配置好了管理国际化资源文件的组件的: org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration

    @Bean
    @ConfigurationProperties(
        prefix = "spring.messages"
    )
    public MessageSourceProperties messageSourceProperties() {
        return new MessageSourceProperties();
    }
    
    @Bean
    public MessageSource messageSource() {
        MessageSourceProperties properties = this.messageSourceProperties(); //private String basename = "messages";
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        if (StringUtils.hasText(properties.getBasename())) {
            messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(properties.getBasename())));
        }
    
        if (properties.getEncoding() != null) {
            messageSource.setDefaultEncoding(properties.getEncoding().name());
        }
    
        messageSource.setFallbackToSystemLocale(properties.isFallbackToSystemLocale());
        Duration cacheDuration = properties.getCacheDuration();
        if (cacheDuration != null) {
            messageSource.setCacheMillis(cacheDuration.toMillis());
        }
    
        messageSource.setAlwaysUseMessageFormat(properties.isAlwaysUseMessageFormat());
        messageSource.setUseCodeAsDefaultMessage(properties.isUseCodeAsDefaultMessage());
        return messageSource;
    }
  • 相关阅读:
    window.onload和DOMContentLoaded的区别
    存储
    JSONP的实现原理
    对于一个无线下拉加载图片的页面,如何给每个图片绑定事件
    事件冒泡
    通用的事件绑定函数
    拆解url的各部分
    如何检测浏览器的类型
    DOM节点操作
    es6基本用法
  • 原文地址:https://www.cnblogs.com/But-you/p/10825217.html
Copyright © 2011-2022 走看看