pom.xml导入内容,使用插件:jpinyin
<dependency>
<groupId>com.github.stuxuhai</groupId>
<artifactId>jpinyin</artifactId>
</dependency>
Java获取昵称的首字母
try {
//获取昵称首字母字符
char c = PinyinHelper.getShortPinyin(memberDto.getNickname()).toUpperCase().charAt(0);
if(c >= 65 && c <= 90 ){//如果是A-Z
hpRedisMemberDto.setCode(c);
}else{
hpRedisMemberDto.setCode('#');//否则设置#
}
} catch (PinyinException e) {
hpRedisMemberDto.setCode('#');//设置#
}