上周主要完成了电话记录和短信的获取与显示,其中包括了表情
客户端传来表情之后,转义存入数据库,之后页面显示之前把数据库存的在转义成表情,显示到页面;
框架用的是ssm
第一步:
引用第三方jar包
//添加依赖
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>java-emoji-converter</artifactId>
<version>0.0.1</version>
</dependency>
第二步:
在插入数据库之前,转义对应的字段 就一行代码…
EmojiConverter.getInstance().toAlias(str) 插入数据库
直接贴代码,我这是批量插入,每次插入1000条
List<Telephone> list = new ArrayList<>();
int i = 0;
for (Map map : telephoneList) {
i++;
Telephone telephone = new Telephone();
try {
BeanUtils.populate(telephone, map);
} catch (Exception e) {
}
telephone.setContact(EmojiConverter.getInstance().toAlias(map.get("contact").toString()));//这一行是重点
telephone.setUdid(udid);
telephone.setCreateTime(DateUtil.toTimeStr(Long.parseLong(map.get("createTime").toString())));
list.add(telephone);
if (i == telephoneList.size() || (i % 1000 == 0)) {
this.insert(list);
list.clear();
}
}
第三步:
从数据库读取,显示到页面,就一行代码
EmojiConverter.getInstance().toUnicode(str)
@Override
protected void afterSelect(List list) {
for (Telephone telephone : (List<Telephone>) list) {
telephone.setContact(EmojiConverter.getInstance().toUnicode(telephone.getContact()));//这里是重点
}
}
公司大佬封装好的方法,相当好用!
页面显示效果如下: