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. 在浏览器输入地址
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qh870754310/article/details/83994166