日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

基于JEECG框架,前台VUE,后台java,导入导出

發(fā)布時(shí)間:2023/12/31 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于JEECG框架,前台VUE,后台java,导入导出 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前端-------------------------------------------------------------------------------------------------------

/* 導(dǎo)出 */handleExportXls(fileName){console.log("111111111111111111111111")if(!fileName || typeof fileName != "string"){fileName = "導(dǎo)出文件"}let param = this.getQueryParams();if(this.selectedRowKeys && this.selectedRowKeys.length>0){param['selections'] = this.selectedRowKeys.join(",")}console.log("導(dǎo)出參數(shù)",param)downFile(this.url.exportXlsUrl,param).then((data)=>{if (!data) {this.$message.warning("文件下載失敗")return}if (typeof window.navigator.msSaveBlob !== 'undefined') {window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')}else{let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))let link = document.createElement('a')link.style.display = 'none'link.href = urllink.setAttribute('download', fileName+'.xls')document.body.appendChild(link)link.click()document.body.removeChild(link); //下載完成移除元素window.URL.revokeObjectURL(url); //釋放掉blob對(duì)象}})},// 下載模板e(cuò)xportTemplate(fileName){if(!fileName || typeof fileName != "string"){fileName = "導(dǎo)出文件"}downFile(this.url.exportTemplate).then((data)=>{if (!data) {this.$message.warning("文件下載失敗")return}if (typeof window.navigator.msSaveBlob !== 'undefined') {window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')}else{let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))let link = document.createElement('a')link.style.display = 'none'link.href = urllink.setAttribute('download', fileName+'.xls')document.body.appendChild(link)link.click()document.body.removeChild(link); //下載完成移除元素window.URL.revokeObjectURL(url); //釋放掉blob對(duì)象}})},/* 導(dǎo)入 */handleImportExcel(info){if (info.file.status !== 'uploading') {console.log(info.file, info.fileList);}if (info.file.status === 'done') {if (info.file.response.success) {// this.$message.success(`${info.file.name} 文件上傳成功`);if (info.file.response.code === 201) {let { message, result: { msg, fileUrl, fileName } } = info.file.responselet href = window._CONFIG['domianURL'] + fileUrlthis.$warning({title: message,content: (<div><span>{msg}</span><br/><span>具體詳情請(qǐng) <a href={href} target="_blank" download={fileName}>點(diǎn)擊下載</a> </span></div>)})} else {this.$message.success(info.file.response.message || `${info.file.name} 文件上傳成功`)}this.loadData()} else {this.$message.error(`${info.file.name} ${info.file.response.message}.`);}} else if (info.file.status === 'error') {if (info.file.response.status === 500) {let data = info.file.responseconst token = Vue.ls.get(ACCESS_TOKEN)if (token && data.message.includes("Token失效")) {Modal.error({title: '登錄已過(guò)期',content: '很抱歉,登錄已過(guò)期,請(qǐng)重新登錄',okText: '重新登錄',mask: false,onOk: () => {store.dispatch('Logout').then(() => {Vue.ls.remove(ACCESS_TOKEN)window.location.reload();})}})}} else {this.$message.error(`文件上傳失敗: ${info.file.msg} `);}}},

后端-------------------------------------------------------------------------------------------------------------------

/*** 通過(guò)excel導(dǎo)入數(shù)據(jù)** @param request* @param response* @return*/@RequestMapping(value = "/importExcel", method = RequestMethod.POST)public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response)throws IOException {MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();// 錯(cuò)誤信息List<String> errorMessage = new ArrayList<>();AtomicInteger successLines = new AtomicInteger();AtomicInteger errorLines = new AtomicInteger();for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {MultipartFile file = entity.getValue();// 獲取上傳文件對(duì)象ImportParams params = new ImportParams();params.setTitleRows(2);params.setHeadRows(0);params.setNeedSave(true);try {List<Customer> listCustomers = ExcelImportUtil.importExcel(file.getInputStream(), Customer.class, params);listCustomers.forEach(c->{if(StringUtil.isBlank(c.getCustomerName())){errorMessage.add("發(fā)生異常:第"+((errorLines.get()/1)+1)+"行客戶名稱為空");errorLines.getAndIncrement();return;}else if(StringUtil.isBlank(c.getCustomerType())){errorMessage.add("發(fā)生異常:第"+((errorLines.get()/1)+1)+"行客戶類別為空");errorLines.getAndIncrement();return;}else if( StringUtil.isBlank(c.getIndustry())){errorMessage.add("發(fā)生異常:第"+((errorLines.get()/1)+1)+"行客戶行業(yè)為空");errorLines.getAndIncrement();return;}List<Map<String, Object>> maps = sysDictService.queryDictByDictCode("customer_category", c.getCustomerType());if(maps!=null && maps.size()>0){c.setCustomerType(maps.get(0).get("itemValue").toString());}List<Map<String, Object>> maps1 = sysDictService.queryDictByDictCode("customer_industry", c.getIndustry());if(maps1!=null && maps1.size()>0){c.setIndustry(maps1.get(0).get("itemValue").toString());}customerService.save(c);successLines.getAndIncrement();});} catch (Exception e) {errorMessage.add("發(fā)生異常:" + e.getMessage());log.error(e.getMessage(), e);} finally {try {file.getInputStream().close();} catch (IOException e) {log.error(e.getMessage(), e);}}}return ImportExcelUtil.imporReturnRes(errorLines.get(), successLines.get(),errorMessage);}/*** 導(dǎo)出excel** @param request* @param customer*/@RequestMapping(value = "/exportXls")public ModelAndView exportXls(Customer customer, HttpServletRequest request) {// Step.1 組裝查詢條件QueryWrapper<Customer> queryWrapper = QueryGenerator.initQueryWrapper(customer, request.getParameterMap());//Step.2 AutoPoi 導(dǎo)出ExcelModelAndView mv = new ModelAndView(new JeecgEntityExcelView());//update-begin--Author:kangxiaolin Date:20180825 for:[03]客戶導(dǎo)出,如果選擇數(shù)據(jù)則只導(dǎo)出相關(guān)數(shù)據(jù)--------------------String selections = request.getParameter("selections");if(!oConvertUtils.isEmpty(selections)){queryWrapper.in("id",selections.split(","));}//update-end--Author:kangxiaolin Date:20180825 for:[03]客戶導(dǎo)出,如果選擇數(shù)據(jù)則只導(dǎo)出相關(guān)數(shù)據(jù)----------------------List<DictModel> categorys = sysDictService.getDictItems("customer_category");List<DictModel> industrys = sysDictService.getDictItems("customer_industry");List<Customer> pageList = customerService.list(queryWrapper);pageList.forEach(c->{if(categorys!=null && categorys.size()>0){categorys.forEach(cat->{if(cat.getValue().equals(c.getCustomerType())){c.setCustomerType(cat.getTitle());}});}if(industrys!=null && industrys.size()>0){industrys.forEach(ind->{if(ind.getValue().equals(c.getIndustry())){c.setIndustry(ind.getTitle());}});}});//導(dǎo)出文件名稱mv.addObject(NormalExcelConstants.FILE_NAME, "客戶列表");mv.addObject(NormalExcelConstants.CLASS, Customer.class);LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();ExportParams exportParams = new ExportParams("客戶列表數(shù)據(jù)", "導(dǎo)出人:"+user.getRealname(), "導(dǎo)出信息");mv.addObject(NormalExcelConstants.PARAMS, exportParams);mv.addObject(NormalExcelConstants.DATA_LIST, pageList);return mv;}/*** 導(dǎo)出模板** @param*/@RequestMapping(value = "/exportTemplate")public ModelAndView exportTemplate() {List<Customer> pageList = new ArrayList<>();//Step.2 AutoPoi 導(dǎo)出ExcelModelAndView mv = new ModelAndView(new JeecgEntityExcelView());//導(dǎo)出文件名稱mv.addObject(NormalExcelConstants.FILE_NAME, "客戶列表導(dǎo)入模板");mv.addObject(NormalExcelConstants.CLASS, Customer.class);LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();ExportParams exportParams = new ExportParams("客戶列表數(shù)據(jù)", "導(dǎo)出人:"+user.getRealname(), "導(dǎo)出信息");mv.addObject(NormalExcelConstants.PARAMS, exportParams);mv.addObject(NormalExcelConstants.DATA_LIST, pageList);return mv;}

總結(jié)

以上是生活随笔為你收集整理的基于JEECG框架,前台VUE,后台java,导入导出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。