我是靠谱客的博主 朴素信封,最近开发中收集的这篇文章主要介绍jeecg导出改装(多表关联导出 ),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

前言

jeecg导出 只能导出单表或者主子表。但是往往写的报表(关联很多表)也导出需要

源代码

	/**
    * 导出excel
    *
    * @param request
    */
   protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title) {
        // Step.1 组装查询条件
        QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<T> pageList = service.list(queryWrapper);
        List<T> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }

        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.CLASS, clazz);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

改动之后

    /**
     * 自定义导出excel
     *
     * @param request
     */
    protected ModelAndView customExportXls(HttpServletRequest request, T object, Class<T> clazz, String title,List<T> pageList) {
        // Step.1 组装查询条件
        // QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
        // Step.2 获取导出数据
        // List<T> pageList = service.list(queryWrapper);

        List<T> exportList = null;
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.CLASS, clazz);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }
  1. 其实改动并不大 只需要将你查询的集合 传进来
    把List pageList = service.list(queryWrapper); 给替换掉就行了。

业务代码实现

    /**
    * 导出excel
    *
    * @param request
    * @param dormSubsidy
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, DormSubsidy dormSubsidy) {
		QueryWrapper<DormSubsidy> queryWrapper = QueryGenerator.initQueryWrapper(dormSubsidy, request.getParameterMap());
		queryWrapper.orderByDesc("gzfdd");
		List<DormSubsidy> list = dormSubsidyService.list(queryWrapper);
		return super.customExportXls(request,dormSubsidy,DormSubsidy.class,"公租房补贴",list);
    }

最后

以上就是朴素信封为你收集整理的jeecg导出改装(多表关联导出 )的全部内容,希望文章能够帮你解决jeecg导出改装(多表关联导出 )所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部