spring boot + ureport2集成

UReport2是一款基于架构在Spring之上纯Java的高性能报表引擎,通过迭代单元格可以实现任意复杂的中国式报表;在UReport2中,提供了全新的基于网页的报表设计器,可以在Chrome、Firefox、Edge等各种主流浏览器运行(IE浏览器除外)。使用UReport2,打开浏览器即可完成各种复杂报表的设计制作。

一、搭建ureport2

  1. 搭建maven项目(目前用idea搭建,spring boot框架)
  2. 在pom.xml中添加先关依赖在pom.xml中添加先关依赖

(1) Ureport2的相关依赖代码

<dependencies>标签下添加ureport2依赖

<dependency>

<groupId>com.bstek.ureport</groupId>

<artifactId>ureport2-console</artifactId>

<version>[version]</version>

</dependency>

(2)连接数据库的相关依赖(MySQL)(只搭建Ureport2可以不添加数据库)

<dependencies>标签下添加 MySQL依赖

<dependency>

<groupId>commons-dbcp</groupId>

<artifactId>commons-dbcp</artifactId>

<version>[version]</version>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>[version]</version>

</dependency>

(3)Springboot相关依赖

<dependencies>标签下添加springboot依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<project>标签下添加springboot依赖

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>[version]</version>

</parent>

1、在src/main/resources下创建application.properties文件
配置数据库连接

## 更改 ureport2 的保存目录(需真实存在的目录)

# ureport.fileStoreDir=G:/tool/ureportfiles

##

## 如若不需要更改:

## 1.web项目:默认在项目web\web-inf\ureportfiles下

## 2.spring boot项目:

##   C:\Users\用户名\AppData\Local\Temp\tomcat-docbase.??.8080\WEB-INF\ureportfiles 下

 

# 数据库链接 数据源配置

spring.datasource.url=jdbc:mysql://localhost:3306/ag_auth

spring.datasource.username=root

spring.datasource.password=123456

spring.datasource.driverClassName=com.mysql.jdbc.Driver

在src/main/resources 下创建 context.xml 文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <import resource="classpath:ureport-console-context.xml"/>

 

    <!-- 引入配置文件 -->

    <bean id="propertyConfigurer" parent="ureport.props">

        <property name="location">

            <!-- 读取配置文件 -->

            <value>classpath:application.properties</value>

        </property>

    </bean>

</beans>
  1. 在src/main/java下创建 com.bstek.ureport.test 包 package
  2. 在com.bstek.ureport.test包下创建Application.java 文件在
package com.bstek.ureport.test;
import com.bstek.ureport.console.UReportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

/**
 * 加载对应的xml配置文件
 */
@ImportResource("classpath:context.xml")
/** 指定类为应用启动类 */
@SpringBootApplication
public class Application {
    /**
     * main 函数
     */
    public static void main(String[] args) {
        /** main方法中通过SpringApplication的run方法启动应用。 */
        SpringApplication.run(Application.class, args);
    }
    /**
     * 进行注册Servlet
     * 配置 UReport2 需要使用到的servlet
     */

    @Bean
    public ServletRegistrationBean buildUReportServlet() {
        /**
         * @param  servlet
         * @param  urlMappings 值为“/ureport/*”的 urlMappings 是一定不能变的,否则系统将无法运行。
         */
        return new ServletRegistrationBean(new UReportServlet(), "/ureport/*");
    }
}

二、运行main()

  1. 点击Application.java 文件 → 右键 → 点击(run’Application.main()’)
    在这里插入图片描述

三、验收结果

  1. 在浏览器输入地址
    在这里插入图片描述
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答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项目的简要步骤。根据具体情况,可能会有一些细微的调整和配置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值