SPRINGMVC return Chinese character garbled problem

Source: Internet
Author: User

SPRINGMVC's @responsebody annotations can convert the object returned by the request method directly to a JSON object, but when the return value is string, Chinese is garbled because the string conversion and the object conversion use two converters. and string Converter fixed in the conversion code "ISO-8859-1", the network is also a variety of solutions, there is through the configuration bean encoding, also has its own rewrite converter, I have tried many times here, can only solve their own.


The first type: Add produces= "Text/html;charset=utf-8 in @requestmapping


Second: In the MVC configuration, the spring version must be 3.1 or later to be configured

<mvc:annotation-driven>
<mvc:message-converters register-defaults= "true" >
<bean class= "Org.springframework.http.converter.StringHttpMessageConverter" >
<constructor-arg value= "UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>


SPRINGMVC return Chinese character garbled problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.