一、OCUpload(One Click Upload)
第一步:将js文件引入页面
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.ocupload-1.1.2.js"></script>
第二步:在页面中提供任意一个元素
第三步:调用插件提供的upload方法,动态修改HTML页面元素
<script type="text/javascript">
$(function(){
//页面加载完成后,调用插件的upload方法,动态修改了HTML页面元素
$("#button-import").upload({
action:"regionAction_importXls.action",
name:"regionFile"
});
});
</script>
第四步:在服务端接收上传的文件
在Action中提供一个File类型的属性,名称和上传的文件输入框名称一致regionFile
@Controller
@Scope("prototype")
public class RegionAction extends BaseAction<Region>{
//属性驱动,接收上传的文件
private File regionFile;
public void setRegionFile(File regionFile) {
this.regionFile = regionFile;
}
//上传excel
public String importXls(){
System.out.println(regionFile);
return NONE;
}
二、pinyin4J
1. <!-- 引入pinyin4J的依赖 -->
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
2.测试
@Test
public void test1(){
//河北省 石家庄市 桥西区
String province = "河北省";
String city = "石家庄市";
String district = "桥西区";
//简码---->>HBSJZQX
province = province.substring(0, province.length() - 1);
city = city.substring(0, city.length() - 1);
district = district.substring(0, district.length() - 1);
String info = province + city + district;
String[] headByString = PinYin4jUtils.getHeadByString(info);
String shortcode = StringUtils.join(headByString);
System.out.println(shortcode);
//城市编码---->>shijiazhuang
String citycode = PinYin4jUtils.hanziToPinyin(city, "");
System.out.println(citycode);
}
原文地址:https://www.cnblogs.com/naixin007/p/9096091.html