第一种方法,[参考链接](https://segmentfault.com/q/1010000002522525/a-1020000002522849)
该方法未尝试,进行xml配置时提示错误.不建议使用
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
第二种方法。[参考内容](https://stackoverflow.com/questions/6049523/how-to-configure-spring-mvc-3-to-not-return-null-object-in-json-response#answer-6049967)
在你要输出的数据的类加上
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)