Springboot集成UReport2
1.pom.xml引入依赖
<dependency> <groupId>com.bstek.ureport</groupId> <artifactId>ureport2-console</artifactId> <version>2.2.9</version> </dependency>
2.编写config配置类
@Configuration @ImportResource("classpath:context.xml") @Slf4j public class UReportConfig implements BuildinDatasource { @Resource private DataSource dataSource; //注册servlet组件 @Bean public ServletRegistrationBean registrationBean() { return new ServletRegistrationBean(new UReportServlet(), "/ureport/*"); } @Override public String name() { return "myDataSource"; } @Override public Connection getConnection() { try { return dataSource.getConnection(); } catch (SQLException e) { log.error("uReport 数据源 获取连接失败!-{}", e.getMessage()); } return null; } }
3.resources下添加相关配置文件
1) 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.xsd"> <import resource="classpath:ureport-console-context.xml"/> <bean id="propertyConfigurer" parent="ureport.props"> <property name="location"> <value>file:${config.path}/ureport-config.properties</value> </property> </bean> </beans>
2) ureport-config.properties
#ureport报表xml文件存放目录
ureport.fileStoreDir=F:\\work\\yyglpt\\service-test\\src\\main\\resources\\report
3) application.properties中添加指定${config.path}
config.path=F:\\work\\yyglpt\\service-test\\src\\main\\resources
4.编写相应Service:
1) 给Service起一个标识名
2) 方法的3个参数是固定写法,不能更改
@Service("roadService") public class RoadService { /** * 路产管理月报 * @param dsName * @param datasetName * @param parameters * @return */ public List<RoadManageReport> queryRoadManageReport(String dsName, String datasetName, Map<String, Object> parameters) { String month = (String) parameters.get("month"); List<RoadManageReport> list = initRoadManageReports(); for (RoadManageReport report : list) { report.setMonthSum(getMonthSum()); report.setYearSum(getYearSum(month)); } return list; } }
5.查看报表引擎
浏览器输入: 项目ip:端口/ureport/designer 即可访问UReport报表引擎
6.数据源配置
1) 数据源配置
2) 数据集配置
3) 刷新数据集
7.编辑报表
8.预览报表/访问真实路径报表
预览: http://127.0.0.1:8085/ureport/preview?_u=p&month=2月
访问真实路径(roadManageReport.ureport.xml是该报表保存的文件名): http://127.0.0.1:8085/ureport/preview?_u=file:roadManageReport.ureport.xml&month=2月
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
2020-05-08 SpringBoot集成SpringSecurity