springMvc 配置 UReport2

参考:https://blog.csdn.net/qq_42207808/article/details/112258835

 

1.配置pom.xml

引入目前最新得2.2.9版本

            <dependency>
                <groupId>com.bstek.ureport</groupId>
                <artifactId>ureport2-console</artifactId>
                <version>2.2.9</version>
            </dependency>

 

2.web.xml配置

<!-- ureport2接口 -->
<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>
 

 

3.spring-context.xml配置(这里我配置在了application.xml中)

mvc直接引入ureport xml配置即可,并引入配置文件,如果有properties就用现在得,没有就新建

<!--引入ureport2-->
<import resource="classpath*:ureport-console-context.xml" />
<bean id="propertyConfigurer" parent="ureport.props">
    <property name="location" value="classpath:/properties/dangjian.properties"/>
</bean>

 

4.properties配置

#ureport固定配置(fileStoreDir默认为tomact启动下得WEB-INF下面得ureportfiles文件夹,可以自定义路径ureport.fileStoreDir=E:/work/ureportfiles)
ureport.fileStoreDir=ureportfiles
ureport.disableHttpSessionReportCache=false
ureport.disableFileProvider=false
ureport.debug=true

 

5.新建类实现BuildinDatasource接口,用以配置项目内置数据源

package com.jeeplus.modules.ureport;
 
import com.alibaba.druid.pool.DruidDataSource;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import com.jeeplus.common.utils.SpringContextHolder;
import org.springframework.stereotype.Component;
 
import java.sql.Connection;
import java.sql.SQLException;
 
/**
 * 内置数据源
 * @author jsy
 * @version 2021/1/4
 **/
@Component
public class ReportDateSource implements BuildinDatasource {
 
    private DruidDataSource druid = SpringContextHolder.getBean(DruidDataSource.class);
 
    @Override
    public String name() {
 
        return "mysql_druid";
    }
 
    @Override
    public Connection getConnection() {
 
        try {
            return druid.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
 

 

6.启动项目访问(关于URL下述的URL

http://localhost:9006/ureport/designer 中,需要根据项目情况修改9006端口

 

注:报表设计器表达式校验依赖于Antlr4,表达式报错得话请pom引入Antlr4

<dependency>
    <groupId>org.antlr</groupId>
    <artifactId>antlr4-runtime</artifactId>
    <version>4.9.1</version>
</dependency>

 

posted @ 2024-06-05 13:52  正怒月神  阅读(38)  评论(0编辑  收藏  举报