导出导入数据到数据库



/**
* 导出检测检验能力模板
* @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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值