/**
* 导出检测检验能力模板
* @param response
* @param redirectAttributes
*/
@RequestMapping(value = "import/template")
public void importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
String fileName = "授权签字人申请汇总表导入模板.xlsx";
List<TestAbilityEntity> list = Lists.newArrayList();
try {
new ExportExcel("授权签字人申请汇总表", AutographEntity.class, 2).setDataList(list).write(response, fileName).dispose();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 导入检验能力数据
* @param file
* @param redirectAttributes
* @return
*/
@RequestMapping(value = "import", method=RequestMethod.POST)
public String importFile(MultipartFile file, RedirectAttributes redirectAttributes){
try {
ImportExcel ei = new ImportExcel(file, 1, 0);
List<AutographEntity> list = ei.getDataList(AutographEntity.class);
for(AutographEntity autographEntity:list){
autographService.save(autographEntity);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return "redirect:"+Global.getAdminPath()+"/qaback/Autograph/?repage";
}
jsp页面上的方法
$(document).ready(function() {
/* $("#btnExport").click(function(){
top.$.jBox.confirm("确认要导出用户数据吗?","系统提示",function(v,h,f){
if(v=="ok"){
$("#searchForm").attr("action","${ctx}/sys/user/export");
$("#searchForm").submit();
}
},{buttonsFocus:1});
top.$('.jbox-body .jbox-icon').css('top','55px');
}); */
$("#btnImport").click(function(){
$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
bottomText:"导入文件不能超过5M,仅允许导入“xls”或“xlsx”格式文件!"});
});
});
jsp页面上的按钮
<div id="importBox" class="hide">
<form id="importForm" action="${ctx}/qaback/Autograph/import" method="post" enctype="multipart/form-data"
class="form-search" style="padding-left:20px;text-align:center;" οnsubmit="loading('正在导入,请稍等...');"><br/>
<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>
<input id="btnImportSubmit" class="btn btn-primary" type="submit" value=" 导 入 "/>
<a href="${ctx}/qaback/Autograph/import/template">下载模板</a>
</form>
</div>