Spring集成Jackson输出非Null数据之XML配置
来源:互联网 发布:sqlserver 复制表 编辑:程序博客网 时间:2024/05/16 14:19
Spring集成Jackson之XML配置
以下为在Spring中集成Jackson输出Json数据功能,在输出数据中不包含Null数据;具体输出数据内容信息控制详见:org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
下面直接贴实现代码:
1、servlet-context.xml配置信息:
<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"> <!-- config jackson 不输出Null数据 --> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <beans:bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <beans:property name="objectMapper"> <beans:bean class="org.codehaus.jackson.map.ObjectMapper"> <beans:property name="serializationInclusion"> <beans:value type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion">NON_NULL</beans:value> </beans:property> </beans:bean> </beans:property> </beans:bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 自动扫描com.baobaotao.web 包下的@Controller标注的类控制器类 --> <context:component-scan base-package="com.app.*" /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean></beans:beans>
2、Controller的写法,注意需要加 @ResponseBody:
** * 查询列表数据 * @param request Request * @param response Response * @return ModelMap */ @ResponseBody @RequestMapping("/list") public ModelMap getList(HttpServletRequest request, HttpServletResponse response) { ModelMap modelMap = new ModelMap() ; try { UserObject obj = ....; modelMap.addAttribute(obj); } catch(Exception e) { e.printStackTrace(); } return modelMap ; }
0 0
- Spring集成Jackson输出非Null数据之XML配置
- Spring MVC 集成 jackson-dataformat-xml 问题
- spring mvc3 Jackson输出null转为空串两种解决方法
- Spring mvc3 jackson输出null为空字符串问题
- Spring之AOP(非XML配置)
- spring-mybatis集成 xml配置
- spring springmvc jackson在ajax返回时,不输出null值对应的属性
- Spring mvc jackson输出null为空字符串、单引号、字段和数字加引号
- Spring HttpMessageConverter 之 Jackson
- Spring HttpMessageConverter 之 Jackson
- spring-mybatis集成的xml配置详解,
- AAARedis 缓存 + Spring 的集成示例(以非XML方式配置,多了一个缓存接口)
- Spring mvc jackson输出null为空字符串、单引号、字段和数字加引号问题Spring mvc3 jackson输出null为空字符串、单引号、字段和数字加引号问题
- spring mvc json jackson 配置
- spring与hibernate集成--spring配置文件applicationContext.xml的配置:
- spring使用jackson实现json输出
- spring使用jackson实现json输出
- Spring AOP之XML配置
- Android Studio 快捷键盘
- 适配器
- How to build & install GLFW 3 and use it in a Linux project
- JDBC
- 设计模式
- Spring集成Jackson输出非Null数据之XML配置
- sizeof()和 strlen()函数
- 【OpenCV入门教程之二】 一览众山小:OpenCV 2.4.8 or OpenCV 2.4.9组件结构全解析
- 基本的SQl语句:update table1 set field1=value1 where 范围
- 20140225 服务器远程桌面连接错误
- oracle10查看用户权限
- AutoMapper在MVC中的运用04
- fgets()和fputs()函数
- STL中用erase()方法遍历删除元素