java @ResponseBody返回值中去掉NULL字段
需要同时添加两个位置:
1、annotation-driven过滤
<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="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
<property name="serializationInclusion">
<util:constant static-field="com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL" />
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
2、RequestMapping过滤
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean id="jacksonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
<property name="serializationInclusion">
<util:constant static-field="com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL" />
</property>
</bean>
</property>
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>application/x-www-form-urlencoded</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>image/jpeg</value>
<value>image/png</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
java @ResponseBody返回值中去掉NULL字段的更多相关文章
- 【Spring Boot-技巧】API返回值去除为NULL的字段
简介 在前后端分离的微服务时代,后端API需要良好的规范.本篇主要将一个数据返回时的一个小技巧-- 过滤为空字段 解决痛点:将有效解决数据传输过程中的流量浪费. 组件简介 Jackson Object ...
- mysql中的null字段值的处理及大小写问题
在MySQL中,NULL字段的处理,需要注意,当在处理查询条件中有NULL,很有可能你得到的值不是想要的,因为,在MySQL中,判断NULL值相等(=)或者不等(!=)都会返回false.主要出现在常 ...
- Oracle 11g对大表中添加DEFAULT值的NOT NULL字段速度有大幅度的提升
在一张2000万的表上增加了一个字段并字段一个默认值,执行这条语句(alter table tablename add new_col default ‘col’)一个小时没有执行完,问我有没有其他解 ...
- Jmeter_Beanshell 返回值中提取参数值
Jmeter_Beanshell 返回值中提取参数值[准备环境]: ①Jmeter版本:5.1,JDK:1.8 ②前置条件:将json.jar包置于..\apache-jmeter-5.1\lib\ ...
- 使用FindControl("id")查找控件 返回值都是Null的问题
做了一个通过字符串ID查找页面控件并且给页面控件赋值的功能,过程中遇到了this.FindControl("id")返回值都是Null的问题,记录一下解决办法. 问题的原因是我所要 ...
- void * 和 void 在函数返回值中的区别
一个很容易糊涂的问题. 在函数的返回值中, void 是没有任何返回值, 而 void * 是返回任意类型的值的指针. 还是看代码吧: #include <stdlib.h> #inclu ...
- 关于readdir返回值中struct dirent.d_type的取值有关问题(转)
关于readdir返回值中struct dirent.d_type的取值问题 原网页链接 http://www.gnu.org/software/libc/manual/html_node/Direc ...
- shell http请求&处理返回值获取其中某个字段的值
并且第一个接口的返回值中部分参数得作为第二个接口的入参,所以做了如下shell验证 第一个接口返回的response body串: { "bizCode": "1&quo ...
- java~api返回值的标准化
api返回值的标准化 例如 {"status":200,"message":"操作成功","data":"{\ ...
随机推荐
- Launching the Debugger Automatically
You can set up your application to start Visual Studio when you launch the application from Windows. ...
- C文件的格式化工具(astyle)
工具简介 astyle用于格式化 C,C++,C#, Java等文件,方便将代码风格转变成预期的效果.如改变缩进方式.括号风格等等. 工具的安装 环境 ubuntu 14.04 $apt-get in ...
- BeanUtils.copyProperties和PropertyUtils.copyProperties的使用区别
http://caoyaojun1988-163-com.iteye.com/blog/1871316
- LintCode MinStack
Implement a stack with min() function, which will return the smallest number in the stack. It should ...
- AFNetworking 3.0
AFN 一.什么是AFN 全称是AFNetworking,是对NSURLConnection的一层封装 虽然运行效率没有ASI高,但是使用比ASI简单 在iOS开发中,使用比较广泛 AFN的githu ...
- 数论 UVALive 2756
这道题目考察的n个不同的数环形排列,每次相邻两个数交换位置,这样由正序转变成逆序所需操作的最小次数t. 公式:环形排列:t= n/2*(n/2 - 1)/2 + (n+1)/2* ((n+1)/2 - ...
- Eclipse+Tomcat搭建https环境
一.首先在本地建立一个keystore文件 用命令:keytool -v -genkey -alias tomcat -keyalg RSA -keystore c:/tomcat.keystore ...
- PHP 类中的魔术方法
定义: PHP类中以两个下画线“__”开头的方法被称为魔术方法. 分类: 例如:构造方法:__construct:析构方法:__destruct:动态重载:__set().__get().__call ...
- Windows环境下npm install常见错误
Windows环境下npm install安装包依赖时,常出现一些错误,下面为个人解决办法: 错误一 缺少python环境: G:\nodejs\moviesite\node_modules\bcry ...
- python logging模块
1.logging模块提供了四个组件logger:日志类,有两个功能1)配置日志的等级,处理器handler,过滤器filterlogger.setLevel(logging.INFO)logger. ...