- 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