UReport使用总结

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

项目地址

安装与配置

  1. 创建一个maven项目,在pom.xml中添加依赖
<dependency>
	<groupId>com.bstek.ureport</groupId>
	<artifactId>ureport2-console</artifactId>
	<version>[version]</version>
</dependency>
  1. 配置ureport需要的servlet
@ImportResource("classpath:context.xml")
@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}


    /**
	 *    "/ureport/*"  固定写法
	 * @return
	 */
	@Bean
	public ServletRegistrationBean buildUreportServlet(){
		return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
	}
}
  1. 如果将UReport配置到已经存在的spring项目中,同时spring也要加载自己的properties文件,需要进行如下配置:
    在src->main->resources 下创建一个context.properties文件,并且在application类加注解@ImportResource(“classpath: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">
            <!-- spring项目的配置文件 -->
            <value>classpath:application.yml</value>
        </property>

    </bean>

</beans>
  1. 需要加载的自己的properties文件如下ureport.properties
#文件的保存路径 随便配置
ureport.fileStoreDir=E:/web/ureportfiles
ureport.disableFileProvider=false
ureport.debug=true
ureport.disableHttpSessionReportCache=false

到这里,我们就在一个标准的 Maven 项目中加入了 UReport2,运行项目,在浏览器中访问 URL:http://localhost:8080/ureport-demo/ureport/designer,就可以看到 UReport2 的报表设计器界面。

报表保存以及数据源配置

  • 数据库数据源
    在这里插入图片描述
    在这里插入图片描述
    点测试连接 提示成功则保存,就可以选择数据库中的某个表把数据取出来。
  • spring bean数据集
    创建一个bean类
@Component
public class TestBean {
    /**
     * @param dsName  数据源名称
     * @param datasetName 数据集名称
     * @param parameters 外部传入的map
     * @return
     */
  public List<Map<String,Object>> loadReportData(String dsName,String datasetName,Map<String,Object> parameters){
       return null;
    }
    public List<User> buildReport(String dsName,String datasetName,Map<String,Object> parameters){
        return null;
    }
}

在这里插入图片描述添加数据集的时候选择方法就会弹出上面两个在代码中定义的方法名,返回对象如果指定返回对象需要使用全路径即可

  • 内置数据源
@Component
public class TestInDataSource implements BuildinDatasource {
    @Autowired
    private DataSource dataSource;
    @Override
    public String name() {
        return "cluster";
    }
    @Override
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            log.println("========"+throwables.getMessage());
        }
        return null;
    }
}

如果报DataSource为空,在pom.xml中添加依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值