Chinaunix首页 | 论坛 | 博客
  • 博客访问: 823688
  • 博文数量: 247
  • 博客积分: 166
  • 博客等级: 入伍新兵
  • 技术积分: 2199
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-15 16:10
文章分类

全部博文(247)

文章存档

2017年(1)

2015年(63)

2014年(80)

2013年(94)

2012年(9)

分类: Java

2015-07-15 17:08:56

有些model,里面很多属性是null,我们希望过滤掉为null的属性,比如 a = null, b = "kk",传递到前台的只有{"b":"kk"}

点击(此处)折叠或打开

  1. <mvc:annotation-driven>
  2.         <!-- 强化参数接收 -->
  3.         <mvc:argument-resolvers>
  4.             <bean class="org.durcframework.common.form.FormModelMethodArgumentResolver" />
  5.         </mvc:argument-resolvers>
  6.           
  7.         <mvc:message-converters>
  8.             <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  9.                 <property name="objectMapper">
  10.                     <bean class="com.fasterxml.jackson.databind.ObjectMapper">
  11.                         <!-- 处理responseBody 里面日期类型 -->
  12.                         <property name="dateFormat">
  13.                             <bean class="java.text.SimpleDateFormat">
  14.                                 <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
  15.                             </bean>
  16.                         </property>
  17.                         <!-- 为null字段时不显示 -->
  18.                         <property name="serializationInclusion">
  19.                             <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
  20.                         </property>
  21.                     </bean>
  22.                 </property>
  23.             </bean>
  24.         </mvc:message-converters>
  25.     </mvc:annotation-driven>

点击(此处)折叠或打开

  1. <mvc:message-converters register-defaults="true">
  2.             <bean
  3.                 class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  4.                 <property name="prefixJson" value="false" />
  5.                 <property name="supportedMediaTypes" value="application/json" />
  6.                 <property name="objectMapper">
  7.                     <bean class="com.fasterxml.jackson.databind.ObjectMapper">
  8.                         <property name="serializationInclusion">
  9.                             <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
  10.                         </property>
  11.                     </bean>
  12.                 </property>
  13.             </bean>
  14.         </mvc:message-converters>


阅读(4101) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~