Chinese characters garbled when using SPRINGMVC request to return a string

Source: Internet
Author: User

@RequestMapping (value= "/askquestion", method = Requestmethod.get, produces = {"Application/json,charset=utf-8"}) @ Responsebodypublic string Askquestion (@RequestParam (value= "content", Required=true) string content,

Returns a string.

The Springmvc @ResponseBody can convert the returned object directly to JSON. However, when the return value is a string, the Chinese language will appear garbled.

is not the same as the converter that returns the object and returns a String. The converter that returns string is Iso-8859-1. So there is garbled

。。

Solution to the online search.

1. When a string is returned, the string result is transferred

return new String ("Hello". GetBytes (), "iso-8859-1");

2. Add @requestmapping Annotations, configure the value of produces

produces = {"Application/json;charset=utf-8"}

3.StringHttpMessageConverter rewrite

Chinese characters garbled when using SPRINGMVC request to return a string

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.