在spring中如果出现java到客户端中传递的json乱码的话,建议使用如下配置
<!--JSON乱码问题配置-->
<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>
本文介绍了一种在Spring框架中解决Java向客户端传递JSON数据时出现乱码问题的方法。通过配置message-converters,使用UTF-8编码和Jackson2进行对象映射,确保了跨平台数据传输的正确性。
1360

被折叠的 条评论
为什么被折叠?



