ureport2使用springbean方式打印导出参数太长问题

因为系统业务需要,只能使用springbean方式打印导出,勾选数据量少的时候一切正常,勾选上千条时参数太长系统报错,记录一下解决办法

handlePrint() {
      this.loading = true;
      pdfFileStream({
        ids: this.Ids,
        file: "file:test.ureport.xml",
      }).then((response) => {
        this.$tools.printPdf(response);//打印pdf流
        this.loading = false;
      });
    },
    

export function pdfFileStream(data) {
  return request({
    url: '/system/printExcle/pdfFileStream',
    method: 'post',
    data: data,
    timeout: 1000000,
    responseType: 'blob',
  })
}


@RestController
@RequestMapping("/system/printExcle")
public class PrintExcleController {
    @Autowired
    private ExportManager exportManager;
/**
     * 打印-pdf流
     * @param resp
     * @throws IOException
     */
    @PostMapping("/pdfFileStream")
    public void pdfFileStream(@RequestBody PrintVo printVo, HttpServletResponse resp) throws IOException
    {
        if (printVo!=null) {
            if(StringUtils.isNotBlank(printVo.getFile())) {
                Map<String, Object> parameters = new HashMap<>();
                parameters.put("file",printVo.getFile());
                if(printVo.getIds()!=null){
                    parameters.put("ids",StringUtils.join(printVo.getIds(), ","));
                }
                fileStream(parameters, resp);
            }
        }

    }
public void fileStream(Map<String, Object> parameters, HttpServletResponse resp) throws IOException
    {
        OutputStream outputStream=resp.getOutputStream();
        try {
            resp.setContentType("application/pdf");
            resp.setHeader("Content-Disposition","inline");
            ExportConfigure configure=new ExportConfigureImpl(parameters.get("file").toString(),parameters,outputStream);
            exportManager.exportPdf(configure);
        }catch(Exception ex) {
            throw new ReportException(ex);
        }finally {
            outputStream.flush();
            outputStream.close();
        }
    }

    public void excel(Map<String, Object> parameters, HttpServletResponse resp) throws IOException
    {
        OutputStream outputStream=null;
        try {
            resp.setContentType("application/octet-stream;charset=ISO8859-1");
            resp.setHeader("Content-Disposition","attachment");
            outputStream=resp.getOutputStream();
            ExportConfigure configure=new ExportConfigureImpl(parameters.get("file").toString(),parameters,outputStream);
            exportManager.exportExcel(configure);
        }catch(Exception ex) {
            throw new ReportException(ex);
        }finally {
            outputStream.flush();
            outputStream.close();
        }
    }
}

  public class PrintVo {

    private String[] ids;
    private String file;
  }

@Component
public class CauseChangeHistoryBean {

    public List<Test> test(String dsName, String datasetName, Map<String, Object> parameters) {
        List<Test> list = new ArrayList<>();
        ......................
        return list;
}
  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: Spring Boot是一种用于创建独立的、基于Spring的应用程序的框架。而UReport2是一种基于Java的开源报表工具,它支持多种数据源,并具有强大的报表设计和生成功能。 要在Spring Boot中引入UReport2的源码,可以按照以下步骤进行操作: 1. 下载UReport2的源码:可以从UReport2的官方网站或GitHub仓库中下载源码。 2. 创建Spring Boot项目:使用IDE或命令行工具创建一个新的Spring Boot项目。 3. 导入UReport2的源码:将下载的UReport2源码复制到Spring Boot项目中的合适位置。 4. 配置依赖:打开Spring Boot项目的pom.xml文件,并添加UReport2的依赖项。这些依赖项包括UReport2的核心库以及相关的依赖库。 5. 配置报表引擎:在Spring Boot项目的配置文件中,配置UReport2的报表引擎。这包括指定报表引擎的类型、数据源的配置等。 6. 编写报表代码:根据项目需求,编写UReport2的报表代码。这包括报表设计、数据源的设置、报表生成和展示等功能。 7. 运行项目:启动Spring Boot项目,访问报表的URL路径,即可进行报表的生成和展示。 通过以上步骤,就可以在Spring Boot项目中成功引入UReport2的源码,并使用其强大的报表功能。注意,在整个过程中,需要按照UReport2的文档和示例进行配置和使用,以确保正确集成和使用UReport2。 ### 回答2: 要引入ureport2源码,首先需要在项目的pom.xml文件中添加ureport2的依赖。可以通过在spring boot项目的pom.xml文件中,添加如下依赖: ```xml <dependency> <groupId>com.bstek.ureport</groupId> <artifactId>ureport2-spring-boot-starter</artifactId> <version>2.9.7</version> </dependency> ``` 引入该依赖后,需要在项目的配置文件中进行相应的配置。在application.properties或application.yml文件中,可以添加以下配置项: ```yaml # ureport配置 ureport: config-file: classpath:ureport/ureport.xml ``` 其中,`ureport.config-file`配置项指定了ureport的配置文件路径。 接下来,在项目中创建ureport配置文件对应的文件夹,并在文件夹中创建ureport.xml配置文件。ureport.xml文件用于配置ureport的一些参数,如数据源、报表资源等。 最后,你可以在spring boot项目中通过注入ureport的相关Bean来使用ureport的功能。例如,可以在Controller中注入`UReportService`或`ReportFileStore`等Bean来实现报表的生成与管理。 总结起来,引入ureport2源码可以通过以下步骤实现: 1. 添加ureport2的依赖到项目的pom.xml文件中。 2. 在项目的配置文件中进行ureport的相关配置。 3. 创建ureport配置文件,并进行相应的配置。 4. 在项目中使用相关的ureport Bean来实现报表的生成与管理。 ### 回答3: 要引入ureport2源码到Spring Boot项目中,可以按照以下步骤操作: 1. 首先,从ureport2的官方仓库(如GitHub)下载ureport2的源码。 2. 创建一个新的Spring Boot项目,可以使用Spring Initializr(https://start.spring.io/)进行快速初始化。确保选择正确的依赖项,如Spring Web和Spring Boot DevTools。 3. 将下载的ureport2源码解压缩,并将其拷贝到Spring Boot项目的src/main/java文件夹下。 4. 打开ureport2源码中的pom.xml文件,并复制其所有的依赖项。 5. 将复制的依赖项粘贴到Spring Boot项目的pom.xml文件中的<dependencies>标签下。 6. 在Spring Boot项目的src/main/resources文件夹下,创建一个ureport文件夹。 7. 将从ureport2源码中复制的src/main/resources/ureport文件夹下的所有文件和文件夹拷贝到Spring Boot项目的src/main/resources/ureport文件夹下。 8. 在Spring Boot项目的src/main/resources/application.properties文件中,添加ureport2所需的数据库配置(如数据库连接url、username和password)。 9. 在Spring Boot项目的src/main/java的启动类中,加入@EnableAutoConfiguration注解来自动配置ureport2所需的bean。 10. 根据需要,可以根据Spring Boot项目的具体情况,调整ureport2的配置文件,如ureport.properties和ureport.xml。 11. 启动Spring Boot项目,ureport2就会被成功引入到项目中。 以上是将ureport2源码引入到Spring Boot项目的简要步骤。根据具体情况,可能会有一些细微的调整和配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值