Grails fix emoji tags in mysql

Source: Internet
Author: User
Tags grails

    1. Domain stores the Emoji property type setting bit byte[]
Class Usertest {    byte[]  namebytes//Store emoji emoticon field    date dateCreated  //grails time Magic field insert automatically gets current system time    date lastupdated  //grails  time Magic field   update automatically gets current system modification time    static constraints = {    }    // Custom get, Set method  conversion byte[] and String    def getName () {        return new String (Namebytes, "UTF-8")    }    def SetName (String name) {        this.namebytes = name.bytes    }}

2.Service Execution Insertcaozuo

   Def insertuser () {        usertest user = new Usertest ()        user.name = "Snow snow??" Smile "        if (!user.save ()) {            throw new Validationexception (" Add user Failed ", user.errors)        }    }

3. Return JSON data

[{' Class ': ' Wxproduct. Usertest "," id ": 1," dateCreated ":" 2015-05-05t13:49:18z "," lastupdated ":" 2015-05-05t13:49:18z "," namebytes ":// MySQL data store byte[][-23,-101,-86,-23,-101,-86,32,//space bytes -16,-97,-111,-111,32,83,109,105,108,101,32,-18,-127,-120]} , "Snow snow?? Smile "//byte[] convert string  ]

Note: 1.mysql5.3 above version supports UTF8MB4 encoding format, but has been tested sometimes MySQL settings utf8mb4 settings have no effect

2.emoji tags?? is 4 bytes, MySQL UTF8 maximum support 3 bytes, UTF8MB4 support 4 bytes, but set database connection character encoding format UTF8MB4 no effect

Grails fix emoji tags in mysql

Related Article

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.