1. 程式人生 > >fastJson與springmvc結合,在spring-mvc.xml中的配置,解決415報錯

fastJson與springmvc結合,在spring-mvc.xml中的配置,解決415報錯

<!-- 會自動註冊了validator  ConversionService  -->
    <mvc:annotation-driven>
        <!--enableMatrixVariables="true">-->
        <mvc:message-converters register-defaults="true">
            <!-- StringHttpMessageConverter編碼為UTF-8,防止亂碼 -->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8"/>
                <property name="supportedMediaTypes">
                    <list>
                        <bean class="org.springframework.http.MediaType">
                            <constructor-arg index="0" value="text"/>
                            <constructor-arg index="1" value="plain"/>
                            <constructor-arg index="2" value="UTF-8"/>
                        </bean>
                        <bean class="org.springframework.http.MediaType">
                            <constructor-arg index="0" value="*"/>
                            <constructor-arg index="1" value="*"/>
                            <constructor-arg index="2" value="UTF-8"/>
                        </bean>
                    </list>
                </property>
            </bean>
 
            <!-- 避免IE執行AJAX時,返回JSON出現下載檔案 -->
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"
                  id="fastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
                <!--<property name="serializerFeature">-->
                <!--這個地方加上這個功能吧,能自己配置一些東西,比如時間的格式化,null輸出""等等-->
                <!--</property>-->
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

相關推薦

fastJsonspringmvc結合spring-mvc.xml配置,解決415

<!-- 會自動註冊了validator ConversionService --> <mvc:annotation-driven> <!--enableMatrixVariables="true">-->

IDEA 匯入或新建maven專案 web.xml配置檔案路徑,配置檔案找不到

某次碰到一個很奇怪的問題,本來專案沒問題的,重新匯入到Idea執行時就跑不起來了。 跑專案時,報如下錯誤: 看報錯好像是log4j2的配置檔案找不到 不可能呀,上次還跑得好好的,檔案也都在。 於是我進入web.xml看看: 怎麼配置檔案都報紅了

spring-mvc.xml配置非同步

<!--配置對應的package名--> <context:component-scan base-package="com.sycamore.asynchronous" />             <

spring—web.xml配置spring監聽器

<!-- spring容器生命週期監聽器配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</l

spring mvc專案配置跨域訪問過濾器

1.在web.xml中配置:<filter> <filter-name>contextFilter</filter-name> <filter-class>xhsoft.fruit.core.filter.WebCon

[Spring]web.xml配置ContextLoaderListener監聽器的作用

在spring的核心配置檔案中,為什麼配置ContextLoaderListener監聽器 <listener> <listener-class>org.springframework.web.context.ContextLoaderLi

mybatis xml是sql語句: Error creating document instance. Cause: org.xml.sax.SAXPa

今天遇到了這個問題,感覺很奇怪,沒有什麼問題,但是還是會報錯。 在網上找了半天,用第二種方法解決了這個問題。第一種方法沒有嘗試。以此來記錄下。 感覺這個問題出現概率很大。要記著呢。 1、使用轉移字元替代 &lt; < &gt; &

pom.xmlwar

第一次搭框架, 剛寫pom.xml的時候<packaging>war</packaging>就報錯, 最後發現是build裡的一個資源找不到 (複製別人的樣例, 這個檔案我還沒有建立) 我這個是資料庫連線的配置文件,補上以後就不報錯了 供

pom.xml無法下載包

小編近日在pom.xml中配置需要下載的jar包時,maven重新整理怎麼都下載不了,報錯: Dependency 'org.springframework:spring-web:4.3.10.RELEASE' not found less... (Ctrl+F1)  Inspec

Spring使用Autowiring自動裝配 解決提示小技巧

1、開啟Settings   輸入Inspections  找到Spring --> Spring Core --> Code --> Autowiring  for  Bean  Class  後面方框裡的顏色預設是Er

mybatis xml是sql語句: Error creating document instance. Cause: org.xml.sax.SAXParseException: The

最近專案折騰了老半天,找了資料才知道是這麼回事。。。 因為語句中有一個小於號“<”,在XML中,會被當成一個頁面元素來解析,不會處理為mysql的SQL語句的組成部分,修改如下: 1、在xml的sql語句中,不能直接用大於號、小於號要用轉義字元 如果用小於

manifest.xmllabel應用名

今天寫程式碼的時候遇到這個錯誤 Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger

2.SpringMVC+Spring+Mybatis整合(2) 配置web.xmlspring-servlet.xmlapplicationContext.xml

web spring-servlet 在 webapp WEB-INF下 applicationContext 在resource資料夾下 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:

spring mvcapplicationContext.xmlspring-mvc.xml的關係

前言 本文參考了: 值得注意的是,【【Spring】淺談ContextLoaderListener及其上下文與DispatcherServlet的區別】中闡述了contextLoaderListener和dispatcherServlet的關係, co

ssm框架web專案spring-mvc.xml解析

spring-mvc.xml配置檔案主要用於配置SpringMVC檢視解析器、控制器、部分靜態資源等。 type:Spring Bean Configuration File <?xml version="1.0" encoding="UTF-8"?> <beans xml

spring mvc 怎麼指定spring.xml配置檔案在web.xml指定

web.xml檔案配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://

菜鳥調(四)——SpringDWR集成配置文件

microsoft his www data editors bing ces myeclipse java 背景簡單介紹:該項目是市信用辦的一個系統,之前好像是一個石家莊的公司負責的。我屬於是半路接手。拿到源代碼後。依據他們給的簡(shao)單(de)明(ke)了(l

Spring spring-mvc.xml

onf conf ack text -c package clas 同時 nbsp Spring配置文件:   1 context:component-scan:     啟動對Dao包進行掃描的功能,同時還聲明了註解(可以移除context:annotation-co

LAMP架構(apachephp結合apache默認虛擬主機)

apache與php的結合 apache默認虛擬主機 一、apache與php結合主配置文件/usr/local/apache2.4/conf/httpd.conf[root@localhost ~]# /usr/local/apache2.4/bin/apachectl graceful (重新加

apachePHP結合apache默認虛擬機

apache與Php 結合 php的默認虛擬主機 php虛擬主機 修改vim /usr/local/apache2.4/conf/httpd.conf 取消ServerName前的#,讓本行生效 添加80端口訪問規則iptables -I INPUT -p tcp --dport 80 -j A