| | |
| | | import cn.hutool.core.text.StrPool; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.pinyin.PinyinUtil; |
| | | import org.aspectj.lang.JoinPoint; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 转小写拼音,字之间以空格分隔,便于调用方按需拼接 / 取首字母 / 拼音搜索 |
| | | * |
| | | * 例:「老张」→ "lao zhang"、「ZhangSan」→ "zhangsan" |
| | | * 英文 / 数字 / 符号原样返回,空值返回 null |
| | | * |
| | | * 注意:底层依赖 hutool-extra 的 {@link PinyinUtil},需要业务模块自行引入拼音引擎依赖 |
| | | * (pinyin4j / TinyPinyin / Bopomofo4j 任选其一),否则运行时会抛 NoClassDefFoundError |
| | | * |
| | | * @param str 字符串 |
| | | * @return 拼音串(保留空格分隔) |
| | | */ |
| | | public static String toPinyin(String str) { |
| | | if (StrUtil.isBlank(str)) { |
| | | return null; |
| | | } |
| | | return PinyinUtil.getPinyin(str); |
| | | } |
| | | |
| | | /** |
| | | * 拼接方法的参数 |
| | | * |
| | | * 特殊:排除一些无法序列化的参数,如 ServletRequest、ServletResponse、MultipartFile |