spring 注解 @ResponseBody 返回JSON 能不能设置他不返回为 null 的值
spring
注解
@ResponseBody
返回
JSON
能不能设置他不返回为
null
的值
java
@RequestMapping(value="/{username}",method=RequestMethod.GET,params="json") @ResponseBody public User show(@PathVariable String username) { return users.get(username); }
披羊皮的狼
11 years, 5 months ago
Answers
设置
jackson
忽略
null
<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>
消逝D存在
answered 11 years, 5 months ago