UReport2 主要功能和亮点
- 完善的网页报表设计器:提供了强大而完善的基于网页的报表设计器,用户可以轻松快速地创建各种复杂的中式报表
- 跨浏览器支持:支持在多种主流浏览器中运行,包括Chrome、Firefox、Edge等
- 兼容性:除IE浏览器之外的其他浏览器上,提供了良好的兼容性和用户体验
首先我们需要创建一个标准的 Maven 项目(具体创建过程可以使用 Eclipse 或其它工具,这里就不再赘述),然后要打开 Maven 的 pom.xml 文件,在其中添加 UReport2 的依赖信息,如下所示:
<dependency> <groupId>com.bstek.ureport</groupId> <artifactId>ureport2-console</artifactId> <version>2.2.2</version></dependency>
在 pom.xml 中添加一个 repository 信息,告诉 Maven 该到这里去下载依赖的包,repository 信息如下所示:
<repository> <id>sonatype</id> <url>https://oss.sonatype.org/content/groups/public/</url></repository>
pom.xml 完整内容
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.bstek.ureport</groupId> <artifactId>ureport2-demo</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.bstek.ureport</groupId> <artifactId>ureport2-console</artifactId> <version>2.2.2</version> </dependency> </dependencies></project>
接下来,我们需要配置一个 UReport2 需要使用到的 servlet。打开项目的 web.xml 文件,在其中添加如下所示的 servlet 配置:
<servlet> <servlet-name>ureportServlet</servlet-name> <servlet-class>com.bstek.ureport.console.UReportServlet</servlet-class></servlet><servlet-mapping> <servlet-name>ureportServlet</servlet-name> <url-pattern>/ureport/*</url-pattern></servlet-mapping>
在这个 servlet 配置当中,值为“/ureport/*”的 url-pattern 是一定不能变的,否则系统将无法运行。
1. 如果项目中没有用 spring,可以直接加载 UReport2 提供的配置文件。打开 web.xml,添加 spring 的 listener 直接加载ureport-console-context.xml配置文件,如下所示:
直接加载 UReport2 的 spring 配置文件
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:ureport-console-context.xml</param-value></context-param>
2. 如果项目中已经用到了 spring,可以在已存在的 spring 配置文件中导入 UReport2的配置文件,如下配置所示:
导入 UReport2 提供的 spring 配置文件
<import resource="classpath:ureport-console-context.xml" />
3. 如果你的 spring 项目中没有 spring 配置文件,可以在 WEB-INF 目录下新建一个名为 context.xml 的配置文件,并在 context.xml 中导入 ureport-console-context.xml 配置文件,如下所示:
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" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <import resource="classpath:ureport-console-context.xml" /></beans>
接下来打开 web.xml,在其中添加一个 spring 提供的 listener,加载我们新建的这个 context.xml 文件,如下所示:
listener 中加载 context.xml 文件
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/context.xml</param-value></context-param>
到这里,我们就在一个标准的 Maven 项目中加入了 UReport2。
运行项目,在浏览器中访问 URL:http://localhost:8080/ureport-demo/ureport/designer
UReport2 的报表设计器界面预览
暂无评论内容