关键代码:
application.java中
register(MultiPartFeature.class);
前端html中:
<form action="${path}/list/uploadExcel" method="post" enctype="multipart/form-data" accept-charset="utf-8"> <p> <input type="file" name="file" /><br /> </p> <input type="submit" value="上传" /> </form>
服务端(有略微的名称编码问题):
<span> </span>@POST @Path("uploadExcel") @Consumes(MediaType.MULTIPART_FORM_DATA) public String uploadExcel( @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition disposition) { String imageName = Calendar.getInstance().getTimeInMillis() + disposition.getFileName(); //File file = new File("D:\\" + imageName); return "import data succeed"; }
by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/