#在 springvmvc 中,接口输出 json 使用 fastjson

当后台返回的VO时,很多属性是没有默认值的,如果前端不做处理就容易出现字符串的显示为 null,空集合容易js报错,fastjson可以配置为空字符串,空集合等

配置方法

<bean id="conversionService"
	class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
</bean>
<mvc:annotation-driven conversion-service="conversionService"
	content-negotiation-manager="contentNegotiationManager">
	<mvc:message-converters register-defaults="true">
		<bean
			class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
			<property name="features">
				<value>WriteDateUseDateFormat,WriteMapNullValue,WriteNullListAsEmpty,WriteNullStringAsEmpty,WriteNullNumberAsZero,WriteNullBooleanAsFalse</value>
			</property>
		</bean>
	</mvc:message-converters>
</mvc:annotation-driven>