zoukankan      html  css  js  c++  java
  • spring mvc json

    问题背景:
        使用了springmvc+velocity的项目,返回json出现了问题

    问题描述:
        出现了406错误
        
    找不到要解析成的头部!

    问题原因:
        缺少json转换配置

    解决办法:
        在对应的servlet配置文件中添加
       
    xmlns:mvc="http://www.springframework.org/schema/mvc" 

    http://www.springframework.org/schema/mvc
               http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 

    <mvc:annotation-driven>
             <mvc:message-converters register-defaults="false">
                <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                            <value>application/*+json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </mvc:message-converters>
         </mvc:annotation-driven>  




  • 相关阅读:
    hdu1410 数学题组合概率 log优化
    Triangle
    Unique Paths II
    Unique Paths
    Pascal's Triangle II
    Pascal's Triangle
    Plus One
    Remove Duplicates from Sorted Array II
    Remove Duplicates from Sorted Array
    Remove Element
  • 原文地址:https://www.cnblogs.com/vvch/p/4871746.html
Copyright © 2011-2022 走看看