jeesite导入导出

$("#btnImport").click(function() {
$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true},
bottomText:"导入文件不能超过5M,仅允许导入“xls”或“xlsx”格式文件!"});
});
$("#btnExport").click(function(){
var index=document.getElementById(\'remark5\').selectedIndex;
var zhi=document.getElementById(\'remark5\').options[index].text;
$("#remark6").val(zhi);
top.layer.confirm(\'确认要导出Excel吗?\', {icon: 3, title:\'系统提示\'}, function(index){
//do something
//导出之前备份
var url = $("#searchForm").attr("action");
var pageNo = $("#pageNo").val();
var pageSize = $("#pageSize").val();
//导出excel
$("#searchForm").attr("action","${ctx}/hp/hpCloth/export");
/* $("#pageNo").val(-1);
$("#pageSize").val(-1);*/
$("#searchForm").submit();

//导出excel之后还原
$("#searchForm").attr("action",url);
$("#pageNo").val(pageNo);
$("#pageSize").val(pageSize);
top.layer.close(index);
});
}); <div>
<form action="${ctx}/hp/hpCloth/import" method="post" enctype="multipart/form-data"
onsubmit="loading(\'正在导入,请稍等...\');"><br/>
<input type="file"/><br/><br/>  
<input type="submit" value="确认导入"/>
<a href="http://www.likecs.com/${ctx}/hp/hpCloth/exportTemp">下载模板</a>
</form>
</div> <li>
<button type="button" data-toggle="tooltip" data-placement="left" title="导入">
<i></i> 导入</button>
</li>
<li>
<button type="button" data-toggle="tooltip" data-placement="left" title="导出">
<i></i> 导出</button>
</li>

//Excel导入数据
@RequestMapping(value = "import")
public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel imEx = new ImportExcel(file, 1, 0);
List<HpCloth> wlCatalogList = imEx.getDataList(HpCloth.class);
for (HpCloth wlCatalog : wlCatalogList) {
try {
hpClothService.save(wlCatalog);
successNum++;
} catch (ConstraintViolationException ex) {
failureMsg.append("<br/>物料名称 " + wlCatalog.getBrand() + " 导入失败:");
List<String> messageList = BeanValidators.extractPropertyAndMessageAsList(ex, ": ");
for (String message : messageList) {
failureMsg.append(message + "; ");
failureNum++;
}
} catch (Exception ex) {
failureMsg.append("<br/>物料名称 " + wlCatalog.getBrand() + " 导入失败:" + ex.getMessage());
}
}
if (failureNum > 0) {
failureMsg.insert(0, ",失败 " + failureNum + " 条数据,导入信息如下:");
}
addMessage(redirectAttributes, "已成功导入 " + successNum + " 条数据" + failureMsg);
} catch (Exception e) {
addMessage(redirectAttributes, "导入物料数据失败!失败信息:" + e.getMessage());
}
return "redirect:" + Global.getAdminPath() + "/wl/wlCatalog/list?repage";
}

@RequestMapping(value = "export")
public String exportFile(HpCloth hpCloth, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "当前库存数据"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<HpCloth> page = hpClothService.findPage(new Page<HpCloth>(request, response), hpCloth);
new ExportExcel("当前库存数据", HpCloth.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出当前库存数据失败!失败信息:"+e.getMessage());
}
return "redirect:" + adminPath + "/hp/hpCloth/list?repage";
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyswwd.html