【Java】【10】后台处理Emoji表情

问题:存到数据库的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 &#128516;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

原文地址:https://www.cnblogs.com/huashengweilong/p/10728216.html