Spring MVC json 轉換 複雜類型用fastjson較好

<!-- 寫在最前邊 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
        <list>
            <!-- 支持Spring自帶的json數據格式轉換 複雜的對象轉換會出錯 -->
            <!--<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  -->
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="defaultCharset" value="UTF-8"/>
                <!-- 加入支持的媒體類型:返回contentType -->
                <property name="supportedMediaTypes">
                    <list>
                        <!-- 這裏順序不能反,一定先寫text/html,不然ie下會出現下載提示 -->
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </list>
    </property>
</bean>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章