spring学习笔记(二十一)springboot_web开发

本文是Spring学习笔记的第二十一部分,聚焦SpringBoot的Web开发中的国际化功能。介绍了SpringMVC和SpringBoot配置国际化的步骤,包括编写配置文件、使用ResourceBundleMessageSource、在页面上展示国际化内容。SpringBoot自动配置了管理资源文件的组件,通过LocaleResolver获取区域信息,实现根据浏览器语言切换国际化显示。最后解释了国际化实现的原理涉及Locale对象和LocaleResolver。
摘要由CSDN通过智能技术生成

4.8 国际化

SpringMVC配置过程:

1)、编写国际化配置文件;

2)、使用ResourceBundleMessageSource管理国际化资源文件

3)、在页面使用fmt:message取出国际化内容

SpringBoot配置过程

步骤:

1)、编写国际化配置文件,抽取页面需要显示的国际化消息

2)、SpringBoot自动配置好了管理国际化资源文件的组件;

@ConfigurationProperties(prefix = "spring.messages")
public class MessageSourceAutoConfiguration {
    
    /**
	 * Comma-separated list of basenames (essentially a fully-qualified classpath
	 * location), each following the ResourceBundle convention with relaxed support for
	 * slash based locations. If it doesn't contain a package qualifier (such as
	 * "org.mypackage"), it will be resolved from the classpath root.
	 */
	private String basename = "messages";  
    //我们的配置文件可以直接放在类路径下叫messages.properties;
    //如果配置文件没有直接放在类路径下,则需要在配置文件中配置spring.message.basename指定基础名
    //如:spring.messages.basename=i18n/login
    
    @Bean
	public MessageSource messageSource() {
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
		if (StringUtils.hasText(this.basename)) {
            //设置国际化资源文件的基础名ÿ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值