文章目录
- 前言
- 一、UReport2是什么?
- 二、使用步骤
- 1.导入POM
- 2.添加context.properties
- 3.编写config配置类
- 4.访问{ip}{端口}/ureport/designer
- 5.配置数据源
- 6.数据集配置
- 7.数据映射
- 8.过滤条件
- 9.行列操作
- 10.行类型
- 1.标题行
- 2.重复表头
- 3.重复表尾
- 4.总结行
- 总结
前言
最近在公司里面要做对报表的修改,原项目用的是第三方报表软件,需要安装第三方软件,有水印,因此选择了基于Apache-2.0协议开源的中式报表引擎UReport2
一、UReport2是什么?
UReport2是一款高性能的架构在Spring之上纯Java报表引擎,通过迭代单元格可以实现任意复杂的中国式报表。
在UReport2中,提供了全新的基于网页的报表设计器,可以在Chrome、Firefox、Edge等各种主流浏览器运行(IE浏览器除外),打开浏览器即可完成各种复杂报表的设计制作。
二、使用步骤
当然该项目是基于springboot的,需要创建springboot工程
1.导入POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-console</artifactId>
<version>2.2.9</version>
</dependency>
<!--连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
2.添加context.properties
在resources目录下创建context.properties文件
内容为:
# 用于定义UReport2中提供的默认基于文件系统的报表存储目录
ureport.fileStoreDir=F:/ureportfiles
3.编写config配置类
@Configuration
//导入ureport-console-context.xml文件
@ImportResource("classpath:ureport-console-context.xml")
@Slf4j
public class ReportConfig implements BuildinDatasource {
//添加 report 的servlet
@Bean
public ServletRegistrationBean<Servlet> ureport2Servlet() {
return new ServletRegistrationBean<>(new UReportServlet(), "/ureport/*");
}
//这一步省略了创建配置文件
@Bean
public UReportPropertyPlaceholderConfigurer UReportPropertyPlaceholderConfigurer(){
UReportPropertyPlaceholderConfigurer propertyConfigurer=new UReportPropertyPlaceholderConfigurer();
propertyConfigurer.setIgnoreUnresolvablePlaceholders(true);
ClassPathResource pathResource=new ClassPathResource("context.properties");
propertyConfigurer.setLocation(pathResource);
return propertyConfigurer;
}
//创建数据源,应该单独在一个配置类中,这里就写在同一个配置类中
@Primary
@Bean
public DataSource businessDataSource(){
DruidDataSource dataSource=new DruidDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/demo?useSSL=false&useUnicode=true&characterEncoding=UTF-8");
dataSource.setUsername("root");
dataSource.setPassword("root");
return dataSource;
}
/**
* 数据源名称
**/
@Override
public String name() {
return "ReportSource";
}
/**
* 获取连接
**/
@Override
public Connection getConnection() {
try {
return businessDataSource().getConnection();
} catch (SQLException e) {
log.error("Ureport 数据源 获取连接失败!");
e.printStackTrace();
}
return null;
}
}
省略的配置文件(因为用配置类配置类了,这里可以不用创建) ![如果不用配置类,那么用该配置文件也可以]()
4.访问{ip}{端口}/ureport/designer
访问成功!
5.配置数据源
6.数据集配置
7.数据映射
映射前
映射后
8.过滤条件
过滤后
9.行列操作
行列操作和excel差不多
选择单元格,右键
10.行类型
1.标题行
不算行内容,此时显示的话行内容是2,标题行只显示1次
2.重复表头
3.重复表尾
重复表尾,和表头差不多,只不过一个是头,一个是尾
4.总结行
总结
UReport2使用起来还是比较方便的,和现有的项目集成起来也比较简单
相关代码查看我的gitee库
相关代码gitee