功能:实现页面输入汉字,后台返回对应汉字拼音
一、效果图
二、代码实现
pom.xml 导入pinyin4j
<!-- https://mvnrepository.com/artifact/com.belerweb/pinyin4j -->
<!-- 中文字符和拼音之间的转换-->
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
Pinyin类
public class Pinyin {
public static String getPinYin(String src) throws Exception {
char[] hz = null;
hz = src.toCharArray();//该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符
String[] py = new String[hz.length];