其他分享
首页 > 其他分享> > SpringMVC——国际化

SpringMVC——国际化

作者:互联网

文章目录

JSP国际化

resources下新建文件夹i18n,一堆properties文件
在这里插入图片描述
各国hello world,分文件放置。中文需要ASC转码

hello=\u4f60\u597d\uff0c\u4e16\u754c\uff01
hello=hello world!

mvc.xml配置

<bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
    <property name="basenames">
        <array>
            <value>i18n.hello</value>
        </array>
    </property>
</bean>

spring标签库引入

<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>

jsp中显示

<spring:message code="hello"/>

点击链接切换语言

mvc.xml配置

<bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver" id="localeResolver"/>
<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
</mvc:interceptors>

url参数添加locale

/hello?locale=en_US

标签:xml,国际化,SpringMVC,locale,mvc,JSP,i18n,hello
来源: https://blog.csdn.net/qq_37284843/article/details/122722664