spring mvc json乱码

Posted 曙光城邦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring mvc json乱码相关的知识,希望对你有一定的参考价值。

    <mvc:annotation-driven>
    	<mvc:message-converters>
    		     <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
		    	<constructor-arg value="UTF-8" />
			</bean>
    	</mvc:message-converters>
    </mvc:annotation-driven>
    

 配置默认转换器的编码格式为UTF-8,源码里是ISO-8859-1

 

-------------------------------

<mvc:annotation-driven>标签开启了13个bean

包含了替换3.1之前的废弃bean

DefaultAnnotationHandlerMapping -> RequestMappingHandlerMapping

AnnotationMethodHandlerAdapter -> RequestMappingHandlerAdapter

AnnotationMethodHandlerExceptionResolver -> ExceptionHandlerExceptionResolver

---------------------------------------13个bean

mvcContentNegotiationManager,
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping,-----------启用了最新的RequestMappingHandlerMapping
mvcCorsConfigurations,
org.springframework.format.support.FormattingConversionServiceFactoryBean#0,
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter,---------启用了最新的RequestMappingHandlerAdapter
mvcUriComponentsContributor,
org.springframework.web.servlet.handler.MappedInterceptor#0,
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,----------启用了最新的ExceptionHandlerExceptionResolver
org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,
org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,
org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,

以上是关于spring mvc json乱码的主要内容,如果未能解决你的问题,请参考以下文章

解决spring-mvc @responseBody注解返回json 乱码问题

spring MVC接收中文乱码问题

spring学习中文乱码问题

Spring MVC @ResponseBody注解返回值中文乱码问题

Spring MVC rest接收json中文格式数据显示乱码

配置由Spring处理json乱码