最近在公司里面要做对报表的修改,原项目用的是第三方报表软件,需要安装第三方软件,有水印,因此选择了基于Apache-2.0协议开源的中式报表引擎UReport2
一、UReport2是什么?UReport2是一款高性能的架构在Spring之上纯Java报表引擎,通过迭代单元格可以实现任意复杂的中国式报表。 在UReport2中,提供了全新的基于网页的报表设计器,可以在Chrome、Firefox、Edge等各种主流浏览器运行(IE浏览器除外),打开浏览器即可完成各种复杂报表的设计制作。
二、使用步骤当然该项目是基于springboot的,需要创建springboot工程
1.导入POM org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-jdbc com.bstek.ureport ureport2-console 2.2.9 com.alibaba druid-spring-boot-starter 1.2.8 2.添加context.properties在resources目录下创建context.properties文件 内容为:
# 用于定义UReport2中提供的默认基于文件系统的报表存储目录ureport.fileStoreDir=F:/ureportfiles 3.编写config配置类 @Configuration//导入ureport-console-context.xml文件@ImportResource("classpath:ureport-console-context.xml")@Slf4jpublic class ReportConfig implements BuildinDatasource {//添加 report 的servlet @Bean public ServletRegistrationBean 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; }} 省略的配置文件(因为用配置类配置类了,这里可以不用创建) ![如果不用配置类,那么用该配置文件也可以](https://img-blog.csdnimg.cn/ca898a98c219495fa0a4d1e5e0d5196a.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA6YW36YW355qE54ix5L2g,size_20,color_FFFFFF,t_70,g_se,x_16) 4.访问{ip}{端口}/ureport/designer访问成功!
5.配置数据源 6.数据集配置7.数据映射
映射前 映射后
8.过滤条件过滤后
9.行列操作行列操作和excel差不多 选择单元格,右键
10.行类型 1.标题行不算行内容,此时显示的话行内容是2,标题行只显示1次
2.重复表头3.重复表尾
重复表尾,和表头差不多,只不过一个是头,一个是尾
4.总结行 总结UReport2使用起来还是比较方便的,和现有的项目集成起来也比较简单
相关代码查看我的gitee库 相关代码gitee