ureport2报表详细使用(一)-集成及配置

来源于   https://blog.csdn.net/oYuHuaChen/article/details/117558459

一、报表简介

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

二、主体功能

  1. UReport2支持创建数据源、添加数据集,并对数据集进行函数、表达式处理;(参考【数据处理】)

  2. UReport2支持对数据集形成可视化报表,包括饼状图、柱状图、曲线图等等(参考【图表展示】)

三、优缺点阐述

优点:

(1)开源、免费,集成即可使用;

(2)轻量级、易集成,工程中添加依赖即可进行集成使用;

(3)支持多函数处理,包括常用函数(sum、count、max、min、avg)、数学函数、字符串函数、日期函数等等;

(4)支持多种图表展示,包括饼状图、柱状图、曲线图、圆环图、雷达图、散点图等等;

缺点:

(1)工程在使用过程中经常出现空指针或者其他报错;

(2)UReport2部分功能不可用,包括导出及多条件表达式SQL查询等;

(3)支持数据源类型少,当前支持:mysql、SQLserver、oracle、db2等

四、集成及配置

UReport2的设计器是基于网页的,配置好一个项目,也就完成了报表设计器的安装。因为 UReport2是一款纯Java的报表引擎,所以它支持现在流行的所有类型J2EE项目,下面将具体介绍基于maven的SpringBoot工程如何集成UReport2 ,并基于当前工程进行一系列的数据处理及报表展示。

4.1 创建springboot工程

1、如果当前本地无springboot工程,提供下载地址:https://github.com/Sonlan/springboot-demo

2、基于已下载的springBoot工程,修改index.html文件内的外部js文件路径,将../修改为../../(原始路径不正确);

4.2 添加依赖

1、在springBoot工程的pom文件dependencies中添加依赖;

  1.  
    <dependency>
  2.  
     <groupId>com.bstek.ureport</groupId>
  3.  
     <artifactId>ureport2-console</artifactId>
  4.  
     <version>2.3.0-SNAPSHOT</version>
  5.  
    </dependency>
  6.  
     
  7.  
    <dependency>
  8.  
     <groupId>com.bstek.ureport</groupId>
  9.  
     <artifactId>ureport2-core</artifactId>
  10.  
     <version>2.3.0-SNAPSHOT</version>
  11.  
    </dependency>
  12.  
            
  13.  
    <dependency>
  14.  
     <groupId>org.slf4j</groupId>
  15.  
     <artifactId>slf4j-api</artifactId>
  16.  
     <version>1.7.7</version>
  17.  
    </dependency>

2、在springBoot工程的pom文件添加repositories;

  1.  
    <repositories>
  2.  
            <repository>
  3.  
                <id>snapshots</id>
  4.  
                <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  5.  
            </repository>
  6.  
            <repository>
  7.  
                <id>sonatype</id>
  8.  
                <url>https://oss.sonatype.org/content/groups/public/</url>
  9.  
            </repository>
  10.  
    </repositories>

3、基于当前工程,创建webapp/WEB-INF目录,工程【main】目录右键【Directory】》输入【webapp】,基于webapp,继续新建directory》【WEB-INF】;

4.3 创建web.xml文件并配置

1、基于已新建【webapp】》【WEB-INF】目录,添加web.xml文件,点击【file】》【Project Structure】》【Facets】》【web】,新增web.xml文件及web resources directory;

  1.  
    说明:
  2.  
    E:\company\idea\IdeaProjects\springboot-demo-master\src\main:为当前我工程的路径
  3.  
    E:\company\idea\IdeaProjects\springboot-demo-master\src\main\webapp\WEB-INF\web.xml(第5步)
  4.  
    E:\company\idea\IdeaProjects\springboot-demo-master\src\main\webapp (第7步)

2、基于步骤6新增的web.xml文件,添加listener及context-param、servlet、servlet-mapping;

  1.  
    <listener>
  2.  
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  3.  
    </listener>
  4.  
     
  5.  
    <context-param>
  6.  
     <param-name>contextConfigLocation</param-name>
  7.  
     <param-value>classpath:ureport-console-context.xml</param-value>
  8.  
    </context-param>
  9.  
     
  10.  
    <servlet>
  11.  
     <servlet-name>ureportServlet</servlet-name>
  12.  
     <servlet-class>com.bstek.ureport.console.UReportServlet</servlet-class>
  13.  
    </servlet>
  14.  
     
  15.  
    <servlet-mapping>
  16.  
     <servlet-name>ureportServlet</servlet-name>
  17.  
     <url-pattern>/ureport/*</url-pattern>
  18.  
    </servlet-mapping>

4.4 创建UreportConfig 文件

1、基于工程启动文件的父节点,创建子文件夹ureport》config,并创建UreportConfig 文件;

  1.  
    package com.song.configuration.ureport.config;
  2.  
     
  3.  
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  4.  
    import org.springframework.boot.web.servlet.ServletRegistrationBean;
  5.  
    import org.springframework.context.annotation.Bean;
  6.  
    import org.springframework.context.annotation.ComponentScan;
  7.  
    import org.springframework.context.annotation.Configuration;
  8.  
    import org.springframework.context.annotation.ImportResource;
  9.  
     
  10.  
    import com.bstek.ureport.console.UReportServlet;
  11.  
     
  12.  
    /**
  13.  
     *  Ureport2 配置类
  14.  
     * @author qiaolin
  15.  
     * @version 2018年5月9日
  16.  
     */
  17.  
     
  18.  
    @ImportResource("classpath:ureport-console-context.xml")
  19.  
    @EnableAutoConfiguration
  20.  
    @Configuration
  21.  
    @ComponentScan(basePackages = "com.song.configuration")
  22.  
    public class UreportConfig {
  23.  
     
  24.  
        @Bean
  25.  
        public ServletRegistrationBean buildUreportServlet(){
  26.  
            return new ServletRegistrationBean(new UReportServlet(), "/ureport/*");
  27.  
        }
  28.  
     
  29.  
    }

2、在配置途中,当缺少包时,需要根据提示自行添加、下载依赖,配置完成,点击resources目录,修改application.properties文件中关于mysql的配置,换成可用库(因为当前springboot工程是以一张user表为例的,所以当前连接的数据库中需要包含user表,囊括id、name、password字段),工程启动的端口号,默认是8080,此处已修改为18090;

  1.  
    #server
  2.  
    server.port=18090
  3.  
    server.tomcat.uri-encoding=utf-8
  4.  
     
  5.  
    #MySQL(当前仅为示例)
  6.  
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  7.  
    spring.datasource.url=jdbc:mysql://localhost:3306/jeesite?characterEncoding=utf8
  8.  
    spring.datasource.username=root
  9.  
    spring.datasource.password=123456

4.5 启动工程

1、当上述均配置完成,进入到启动文件Entry,右键点击【Run Entry】启动工程;

4.6 访问工程

工程成功启动,访问地址为: http://localhost:18090/ureport/designer

 

posted @ 2022-09-14 15:08  苦行者的刀  阅读(8581)  评论(0)    收藏  举报