Commit 807713a4 authored by nie'hong's avatar nie'hong

拼音工具类识别多音字正确拼音

parent 6410a400
...@@ -8,6 +8,8 @@ import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; ...@@ -8,6 +8,8 @@ import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -27,7 +29,7 @@ public class PinYinUtil { ...@@ -27,7 +29,7 @@ public class PinYinUtil {
* @return 中文对应的拼音 * @return 中文对应的拼音
*/ */
public static String getPinYin(String chinese, Boolean firstWord, Boolean appendNonChinese) { public static String getPinYin(String chinese, Boolean firstWord, Boolean appendNonChinese) {
// 6月1日修改前 /* 6月1日修改前
//汉语拼音输出格式 //汉语拼音输出格式
HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat(); HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();
//大小写设置 大写 //大小写设置 大写
...@@ -63,19 +65,30 @@ public class PinYinUtil { ...@@ -63,19 +65,30 @@ public class PinYinUtil {
} }
} }
} }
return stringBuilder.toString(); return stringBuilder.toString();*/
// 6月1日修改后 // 6月1日修改后
// try { String pinyinString = new String();
// Pinyin pinyin = new Pinyin(); try {
// String test = pinyin.translateWithSepNoMark(chinese); // 是否需要将英文字符和拼音拼接
// System.out.println(test); if (appendNonChinese) {
// } catch (PinyinException e) { chinese = RegExUtils.replaceAll(chinese, "[a-zA-Z]", "");
// e.printStackTrace(); }
// } Pinyin pinyin = new Pinyin();
// return null; if (firstWord) {
// 拼音首字母
pinyinString = pinyin.translateFirstChar(chinese);
}else {
// 拼音全拼
String withSepNoMark = pinyin.translateWithSepNoMark(chinese,"");
// 将字符串中的'ü'替换为'v’
pinyinString = withSepNoMark.replace("ü", "v");
}
} catch (PinyinException e) {
e.printStackTrace();
}
// 转为大写
return pinyinString.toUpperCase();
} }
//
} }
...@@ -652,9 +652,9 @@ public class RoleController extends BaseController { ...@@ -652,9 +652,9 @@ public class RoleController extends BaseController {
ew.eq("is_deleted", 0); ew.eq("is_deleted", 0);
ew.eq("status", 1); ew.eq("status", 1);
// 不要这三个单位管理员 统计管理员 互动审核员 // 不要这三个单位管理员 统计管理员 互动审核员
// ew.ne("alias", "dwgly"); ew.ne("alias", "dwgly");
// ew.ne("alias", "tjgly"); ew.ne("alias", "tjgly");
// ew.ne("alias", "hdshy"); ew.ne("alias", "hdshy");
ew.orderByAsc("sortorder"); ew.orderByAsc("sortorder");
ew.orderByDesc("create_time"); ew.orderByDesc("create_time");
List<Role> list = roleService.list(ew); List<Role> list = roleService.list(ew);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment