spring boot整合ureport2笔记

a.添加ureport依赖(根据需要添加其他依赖)
<!--UReport2-->
<dependency>
    <groupId>com.bstek.ureport</groupId>
    <artifactId>ureport2-console</artifactId>
    <version>2.1.5</version>
</dependency>

b.注册服务bean,访问ureport

/**
 * Ureport2配置类
 */
@Configuration
@ImportResource("reportcontext.xml")
public class UreportConfig {

    @Bean
    public ServletRegistrationBean builderUreport(){
        return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
    }
}

c.加载ureport2的配置文件

*在配置文件中可自定义指定ureport保存文件路径(可不指定)

## 更改 ureport2 生成的xml的保存目录(需真实存在的目录
ureport.fileStoreDir=D:\\ureportfiles

新建UReport的配置文件reportcontext.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-3.0.xsd">
    <import resource="classpath:ureport-console-context.xml"/>
    <!-- 引入配置文件 -->
    <bean id="propertyConfigurer" parent="ureport.props">
        <property name="location">
            <!-- 读取配置文件 -->
            <value>classpath:application.properties</value>
        </property>
    </bean>
</beans>

d.启动项目。访问https://localhost:8080/ureport/designer 设计页面

e.ureport2有3中数据源,推荐使用内置数据源

/**
 * UReport2采用内置数据数据源配置
 */
@Component
public class UreportDataSource implements BuildinDatasource {

    private static final Logger log = LoggerFactory.getLogger(UreportDataSource.class);

    @Autowired
    private DataSource dataSource;
    @Override
    public String name() {
        return "内置数据源";
    }

    @Override
    public Connection getConnection() {
        try {
           return dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            log.error("报表数据源初始化错误");
            return null;
        }
    }
}

f.报表设计完成保存后,可以通过

http://host[:port][/context-path]/ureport/preview?_u=file:报表名称 预览

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值