SpringMVC garbled processing and SpringMVC garbled Processing
Recently, the Spring MVC configuration file was modified because of the modification of Spring transactions. However, it was found that garbled characters were generated when AJAX was used to obtain background data. The final result is that a label is added to the SpringMVC configuration file:
<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>
If the <mvc: annotation-driven/> label is added, the configuration will be invalid. Due to the worry, I did not contact the source code. I directly asked du Niang. Some netizens said that adding such code can solve the problem:
<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>
In this case, the editor reports an error, indicating that the annotaion-driver tag cannot contain child elements. I went there, but I was confused by some netizens. Later I found that the XSD file version was lower, so I switched to version 3.2 to solve the problem. Modify the XSD import code, for example:
<? 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 = "The http://www.springframework.org/schema/aop" xmlns: tx = "The 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>
If you are another version, you can also change to another version, address in: http://www.springframework.org/schema/mvc/
Therefore, the solution to each type of problem is limited by its environment and has no technical content. Remember to help other users.