springMvc 国际化时乱码的解决办法

springMvc 处理国际化是前台页面出现乱码,如下所示:
这里写图片描述

假设此时使用的是Session进行国际化(三种国际化都一样),解决办法:
1. 在 springMvc中配置:


    <!--国际化-->
    <bean class="org.springframework.context.support.ResourceBundleMessageSource" id="resourceBundleMessageSource">
        <!--国际化文件资源名-->
        <property name="basename" value="messages"/>
        <!-- 支持UTF-8的中文 -->
        <property name="cacheSeconds" value="0"/>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

2.修改 .properties配置文件的编码:

File ——> Settings --> Editor --> File Encodings下修改
Default Encoding for properties files:为 UTF-8 即可。

3.进行正常的国际化编码

猜你喜欢

转载自blog.csdn.net/annotation_yang/article/details/78373395