SpringMVC的乱码处理

    最近因为修改Spring事务的原因,修改了SpringMVC的配置文件,可是最后发现使用AJAX获取后台数据是出现乱码问题。最后发现是因为SpringMVC配置文件中新增了个标签:

<mvc:annotation-driven/>引起的,因为之前在配置文件有这样的配置:

<bean  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >  
        <property name="messageConverters">  
             <list>  
                 <bean class = "org.springframework.http.converter.StringHttpMessageConverter">  
                    <property name = "supportedMediaTypes">  
                         <list>  
                             <value>text/plain;charset=UTF-8</value>  
                         </list>  
                    </property>  
                 </bean>  
             </list>  
        </property>  
    </bean> 

    如果增加上<mvc:annotation-driven/>标签,则这个配置将会失效。由于着急,没有跟源码,直接问度娘,有网友说加上如此代码问题可以解决:

     <mvc:annotation-driven>
   <mvc:message-converters>
       <bean class="org.springframework.http.converter.StringHttpMessageConverter">
           <property name="supportedMediaTypes">
               <list>
                   <value>application/json;charset=UTF-8</value>
               </list>
           </property>
       </bean>
   </mvc:message-converters>
</mvc:annotation-driven>

      这个时候编辑器报错,说annotaion-driver标签里不能包含子元素。我去,网友怎么呢蒙人呢,后来发现是因为XSD文件版本低了,于是我换成了3.2版本的,问题解决。修改XSD引入代码如:

      <?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

    如果你是其他版本也可以换成其他版本,地址在:http://www.springframework.org/schema/mvc/

    所以每种问题的解决都受其环境局限,没有什么技术含量,记下来万一能帮上其他网友呢。

      

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值