當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
Spring MVC--使用fastjson替换jackson来响应json数据
生活随笔
收集整理的這篇文章主要介紹了
Spring MVC--使用fastjson替换jackson来响应json数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用fastjson替換jackson來(lái)響應(yīng)json數(shù)據(jù)。
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可以自動(dòng)去掃描base-pack下面的包或者子包下面的java文件,如果掃描到有Spring的相關(guān)注解的類,則把這些類注冊(cè)為Spring的bean --><context:component-scan base-package="org.zhangxueliang.controller"/><!-- 使用默認(rèn)的Servlet來(lái)響應(yīng)靜態(tài)文件 --><mvc:default-servlet-handler/><!-- 設(shè)置配置方案 --><mvc:annotation-driven><!-- 設(shè)置不使用默認(rèn)的消息轉(zhuǎn)換器 --><mvc:message-converters register-defaults="false"><!-- 配置Spring的轉(zhuǎn)換器 --><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中實(shí)現(xiàn)HttpMessageConverter接口的轉(zhuǎn)換器 --><bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"><!-- 加入支持的媒體類型:返回contentType --><property name="supportedMediaTypes"><list><!-- 這里順序不能反,一定先寫text/html,不然ie下會(huì)出現(xiàn)下載提示 --><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>總結(jié)
以上是生活随笔為你收集整理的Spring MVC--使用fastjson替换jackson来响应json数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring MVC--使用Jackso
- 下一篇: Java多线程--synchronize