|
楼主 |
发表于 2019-7-4 17:27:06
|
显示全部楼层
前端的导出代码:- /* 导出 */
- handleExportXls() {
- let paramsStr = encodeURI(JSON.stringify(this.getQueryParams()));
- let url = `${window._CONFIG['domianURL']}/${this.url.exportXlsUrl}?paramsStr=${paramsStr}`;
- window.location.href = url;
- }
复制代码 后端的代码:- public ModelAndView exportXls(AmMaterial param, HttpServletRequest request, HttpServletResponse response) {
- // Step.1 组装查询条件
- QueryWrapper<AmMaterial> queryWrapper = QueryGenerator.initQueryWrapper(param, request.getParameterMap());
- try {
- String paramsStr = request.getParameter("paramsStr");
- if (oConvertUtils.isNotEmpty(paramsStr)) {
- String deString = URLDecoder.decode(paramsStr, "UTF-8");
- AmMaterial amMaterial = JSON.parseObject(deString, AmMaterial.class);
- queryWrapper = QueryGenerator.initQueryWrapper(amMaterial, request.getParameterMap());
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- SysUser sysUser = (SysUser)SecurityUtils.getSubject().getPrincipal();
- // SysUser sysUser=JwtUtil.getCurrentUser(request);
- String user = "";
- if(sysUser!=null){
- user = sysUser.getUsername();
- }
- //Step.2 AutoPoi 导出Excel
- ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
- List<AmMaterial> pageList = amMaterialService.list(queryWrapper);
- //导出文件名称
- mv.addObject(NormalExcelConstants.FILE_NAME, "物料信息列表");
- mv.addObject(NormalExcelConstants.CLASS, AmMaterial.class);
- mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("物料信息", "导出人:" + user, "导出信息"));
- mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
- return mv;
- }
复制代码 |
|