Spring转换编码utf-8方式

方式一:修改Spring配置文件(建议使用)

<mvc:annotation-driven>
    <mvc:message-converters register-defaults="true">
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <constructor-arg value="UTF-8"/>
        </bean>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper">
                <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
                    <property name="failOnEmptyBeans" value="false"/>
                </bean>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
View Code

方式二:在action上声明编码格式

@RequestMapping(path="/json",produces = "application/json;charset=UTF-8")

 

posted @ 2018-10-29 20:25  韦邦杠  阅读(1447)  评论(0编辑  收藏  举报