com.yixan.base.web.controller.PinYinController Maven / Gradle / Ivy
package com.yixan.base.web.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.yixan.base.annotation.OperateRecord;
import com.yixan.base.common.enums.OperateType;
import com.yixan.base.core.result.ResponseMessage;
/**
* 汉字转拼音
*
* @author zhaohuihua
* @version C01 2016-02-22
*/
@Controller
@RequestMapping("/actions/pinyin")
@OperateRecord(value = "汉字转拼音", type = OperateType.QUERY)
public class PinYinController {
@ResponseBody
@RequestMapping("all")
public ResponseMessage all(String text) {
ResponseMessage result = new ResponseMessage();
Map map = new HashMap<>();
map.put("short", PinyinHelper.getShortPinyin(text));
map.put("full", PinyinHelper.convertToPinyinString(text, " ", PinyinFormat.WITHOUT_TONE));
map.put("mark", PinyinHelper.convertToPinyinString(text, " ", PinyinFormat.WITH_TONE_MARK));
result.setBody(map);
return result;
}
/**
* 简拼, 你好世界 = nhsj
*
* @param text
* @return
*/
@ResponseBody
@RequestMapping("short")
public ResponseMessage shortPinyin(String text) {
ResponseMessage result = new ResponseMessage();
result.setBody(PinyinHelper.getShortPinyin(text));
return result;
}
/**
* 全拼, 你好世界 = ni hao shi jie
*
* @param text
* @return
*/
@ResponseBody
@RequestMapping("full")
public ResponseMessage withoutTone(String text) {
ResponseMessage result = new ResponseMessage();
result.setBody(PinyinHelper.convertToPinyinString(text, " ", PinyinFormat.WITHOUT_TONE));
return result;
}
/**
* 带音标, 你好世界 = nǐ hǎo shì jiè
*
* @param text
* @return
*/
@ResponseBody
@RequestMapping("mark")
public ResponseMessage withToneMark(String text) {
ResponseMessage result = new ResponseMessage();
result.setBody(PinyinHelper.convertToPinyinString(text, " ", PinyinFormat.WITH_TONE_MARK));
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy