spring mvc4中json的编码配置

由于StringHttpMessageConverter extends AbstractHttpMessageConverter<String>中public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");  默认的编码方式非UTF8如果使用utf8采用如下配置:

<mvc:annotation-driven>
		<mvc:message-converters>
			<!-- json編碼配置 -->
			<bean id="stringHttpMessageConverter"
				class="org.springframework.http.converter.StringHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>text/html;charset=UTF-8</value>  
		                <value>text/json;charset=UTF-8</value>  
		                <value>application/json;charset=UTF-8</value> 
					</list>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>


你可能感兴趣的:(json)