[Java] 纯文本查看 复制代码**1.以下代码是一个文字转拼音的工具类**
import org.springframework.stereotype.Component;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
/**
* pinyin4j汉字转拼音工具类
* @AuThor zhiheng
*
*/
@Component
public class ChangeToPinYin {
//pinyin4j格式类
private HanyuPinyinOutputFormat format = null;
//拼音字符串数组
private String[]pinyin;
//通过构造方法进行初始化
public ChangeToPinYin(){
format = new HanyuPinyinOutputFormat();
/*
* 设置需要转换的拼音格式
* 以天为例
* HanyuPinyinToneType.WITHOUT_TONE 转换为tian
* HanyuPinyinToneType.WITH_TONE_MARK 转换为ti