springboot 集成 UReport2 报表系统

UReport2 生成 excel 文档确实很强大

入门《文档》

1. pom 文件引入 依赖

<properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.bstek.ureport/ureport2-console -->
        <dependency>
            <groupId>com.bstek.ureport</groupId>
            <artifactId>ureport2-console</artifactId>
            <version>2.2.9</version>
        </dependency>

        <!-- mybatis -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.4</version>
        </dependency>
    </dependencies>

2. 添加 servlet 配置 UreportConfig.java

package com.min.demo.config;

import com.bstek.ureport.console.UReportServlet;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@ImportResource("classpath:ureport-console-context.xml")//不加项目能够启动但是会导致加载数据源报错或加载不了
@Configuration
public class UreportConfig implements BuildinDatasource {
	// yml 中需要配置数据源
    @Resource
    DataSource dataSource;
    private Logger log = LoggerFactory.getLogger(getClass());

    @Bean //定义ureport的启动servlet
    public ServletRegistrationBean buildUreportServlet(){
        return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
    }

    @Override
    public String name() {
        return "System";
    }

    @Override
    public Connection getConnection() {

        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            log.error("Ureport 数据源 获取连接失败!");
            e.printStackTrace();
        }
        return null;
    }

}


3. ureport 默认配置 ureport.properties

ureport.disable**加粗样式**HttpSessionReportCache=false

#UReport2默认报表存储
ureport.disableFileProvider=false
ureport.fileStoreDir=d:/ureportfiles
ureport.debug=true

4. application.yml

spring:
  application:
    name: demo
  main:
    allow-bean-definition-overriding: true
  datasource:
    druid:
      url: jdbc:mysql://localhost:3306/ier?useUnicode=true&characterEncoding=utf8&useSSL=false
      username: root
      password: 123456
      driver-class-name: com.mysql.cj.jdbc.Driver
      # 下面为连接池的补充设置,应用到上面所有数据源中
      # 初始化大小,最小,最大
      #初始化连接
      initialSize: 10
      #最小空闲连接
      minIdle: 10
      #最大空闲连接
      #      maxIdle: 0
      #最大活动连接
      maxActive: 100
      # 配置获取连接等待超时的时间,从池中取连接的最大等待时间,单位ms.
      maxWait: 3000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒, 每30秒运行一次空闲连接回收器
      timeBetweenEvictionRunsMillis: 30000
      # 配置一个连接在池中最小生存的时间,单位是毫秒, 池中的连接空闲30分钟后被回收
      minEvictableIdleTimeMillis: 30000
server:
  port: 8090

5. 启动 访问 http://localhost:8090/ureport/designer

在这里插入图片描述

6. 目录结构

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值