springmvc访问返回数据类型格式化json报http status 406 和json时间格式化

1、The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

spring mvc4.3.3

解决:在maven项目下pom文件添加

<dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>2.5.3</version>
  </dependency>


默认springmvc返回的json时间格式是毫秒数,spring xml可以配置转换方式,配置如下

<mvc:annotation-driven>
        <!-- 编码转换 -->
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/plain;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>    
             <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
                <property name="objectMapper">  
                    <bean class="com.fasterxml.jackson.databind.ObjectMapper">  
                        <!-- 处理responseBody 里面日期类型 -->  
                        <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="timeZone" value="GMT+8" />  
                        <!-- 为null字段时不显示 -->  
                        <property name="serializationInclusion">  
                            <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>  
                        </property>                          
                       </bean>  
                    </property>                          
               </bean>        
        </mvc:message-converters>
    </mvc:annotation-driven>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值