When the Spring MVC return type is a string, the returned Chinese becomes "?" Processing

Source: Internet
Author: User

When the Spring MVC return type is a string, the returned Chinese becomes "?" Processing

The Spring controller is as follows

@Controllerclass Simplecontroller {    @ResponseBody    @RequestMapping (value = "/hotel")    publicreturn "{\" status\ ": 0,\" errmsg\ ": Null,\" data\ ": {\" query\ ": \" hotel query \ ", \" num\ ": 65544,\" url\ ": \" Www.test.com\ "}}";}}     

Here using Responsebody, the return value is directly a string, no use to Jackson, if it is to return an object, using the Jackson to JSON, there is no coding problem

Then the hotel inquires a few words all become question marks

Since spring handles the result of a string type with the return value, we need to configure his encoding Stringhttpmessageconverter

    class= "Java.nio.charset.Charset"          factory-method= "forname" >        <constructor-arg value= "UTF-8"/ >    </bean>    <mvc:annotation-driven>        <mvc:message-converters>            class= " Org.springframework.http.converter.StringHttpMessageConverter ">                <constructor-arg ref=" Utf8charset "/ >            </bean>        </mvc:message-converters>    </mvc:annotation-driven> 

When the Spring MVC return type is a string, the returned Chinese becomes "?" Processing

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.