問題:存到數據庫的emoji表情,取出來后,在前端顯示為亂碼
環境:SpringBoot + Oracle(MySQL據說是支持表情的)
解決方案:
引入emoji相關的jar包,使用很方便,不過表情庫不全,最近一次更新還是2017年
<!-- https://mvnrepository.com/artifact/com.vdurmont/emoji-java --> <dependency> <groupId>com.vdurmont</groupId> <artifactId>emoji-java</artifactId> <version>4.0.0</version> </dependency>
轉碼:
//將表情轉碼 String str = "An 【表情1】awesome【表情2】string 【表情3】with a few 【表情4】emojis!"; String result = EmojiParser.parseToAliases(str);
解碼:
//將轉碼后的數據解碼為帶表情的字符串 String str = "An :grinning:awesome :smiley:string 😄with a few :wink:emojis!"; String result = EmojiParser.parseToUnicode(str);
參考博客:
1,Emoji表情后台處理 - qingmulang的博客 - CSDN博客
https://blog.csdn.net/qingmulang/article/details/76098569
2,javascript - 微信模板推送是怎么加上EMOJI表情的? - SegmentFault 思否
https://segmentfault.com/q/1010000012487472?sort=created