Springmvc mybatis MySQL blob Chinese garbled problem processing

Source: Internet
Author: User

Recently use AJAX request SPRINGMVC background query MySQL database, page display Chinese garbled

Initially configured as follows in MyBatis

?
123 <selectid="queryContentById"  resultType = "java.lang.String" parameterType="String">        select text from News where id=#{o}  </select>

Where table News's text field is a BLOB type

The text value so isolated is garbled in the console.

After Google found relevant Resulttype=blob related content without results, and then changed it to Resulttype = "Java.util.Map", and

?
12 byte[] b = (byte[]) map.get("text");String s = newString(b,"utf-8");

Print out S, at this time the Chinese normal display, but the page display is still garbled.

Therefore, the AJAX request, then check the response header information, identified as follows

content-typetext/html;charset=iso-8859-1

Because the database is encoded as UTF-8, the response header information is modified

1234567 @RequestMapping(value = "/queryContentById", method = RequestMethod.GET,produces = "text/plain;charset=UTF-8")public @ResponseBody String queryContentById(@RequestParam("id") String id) throws SQLException, UnsupportedEncodingException {    Map map = (Map) ndrService.queryContentById(id);    byte[] b = (byte[]) map.get("text");    String s = new String(b,"utf-8");    return s;}

Please refer to the following information:

Http://www.itnose.net/detail/6074493.html

Springmvc mybatis MySQL blob Chinese garbled problem 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.