日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring MVC--使用fastjson替换jackson来响应json数据

發布時間:2025/1/21 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring MVC--使用fastjson替换jackson来响应json数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用fastjson替換jackson來響應json數據。

springmvc-config.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsd"><!-- spring可以自動去掃描base-pack下面的包或者子包下面的java文件,如果掃描到有Spring的相關注解的類,則把這些類注冊為Spring的bean --><context:component-scan base-package="org.zhangxueliang.controller"/><!-- 使用默認的Servlet來響應靜態文件 --><mvc:default-servlet-handler/><!-- 設置配置方案 --><mvc:annotation-driven><!-- 設置不使用默認的消息轉換器 --><mvc:message-converters register-defaults="false"><!-- 配置Spring的轉換器 --><bean class="org.springframework.http.converter.StringHttpMessageConverter"/><bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/><bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/><bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/><!-- 配置fastjson中實現HttpMessageConverter接口的轉換器 --><bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"><!-- 加入支持的媒體類型:返回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></mvc:message-converters></mvc:annotation-driven><!-- 視圖解析器 --><bean id="viewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 前綴 --><property name="prefix"><value>/WEB-INF/content/</value></property><!-- 后綴 --><property name="suffix"><value>.jsp</value></property></bean></beans>

總結

以上是生活随笔為你收集整理的Spring MVC--使用fastjson替换jackson来响应json数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。