表单提交导入文件

来源:互联网 发布:suse linux 网络配置 编辑:程序博客网 时间:2024/05/17 08:58

———-html js 提交

<form id="import_form" method="post" enctype="multipart/form-data">    <input type="file" id="import_file" name="path" />   </form>//js:$('#import_form').form('submit', {         url:"/saasoc/historyAccount/downHisAccount.do",success: function(res){    var data=JSON.parse(res);    if(data.state=="ok"){        top.$.messager.alert('温馨提示','导入成功','warning');    }else{        top.$.messager.alert('温馨提示','导入失败','warning');    }  }});

———-Java后台

//@RequestParam("path") CommonsMultipartFile获取导入文件路径public @ResponseBody JsonResp downHisAccount(@RequestParam("path") CommonsMultipartFile files) throws Exception {JsonResp resp = null;ImportParams params = new ImportParams();//第三方导入参数params.setVerifyHanlder(new ImporterVerifyHandler());// 导入数据,files.getInputStream()导入文件,解析导入数据List<ImportAccount> list = ExcelImportUtil.importExcel(    files.getInputStream(), ImportAccount.class, params);//ImportAccount 导入的实体类信息,且加上导入的注解信息/**例如public class ImportAccount {@Excel(name = " 姓名")private String cname; // 姓名}**/if (list.size() > 0 && list != null) {    int his = hisAccountService.addImport(list);    //批量添加操作    if (his == 1) {        resp = new JsonResp(JsonResp.STATE_OK);    } else {        resp = new JsonResp(JsonResp.STATE_ERR);    }} else {    resp = new JsonResp(JsonResp.STATE_ERR);    resp.setErrMsg("该excel文件无数据,请检查!");}return resp;}

———-该方法只使用少于1万条数据的导入

原创粉丝点击