在SpringBoot项目中使用Ureport2报表工具

SpringBoot项目中使用Ureport2报表工具

1.在spring boot项目中使用Ureport2报表工具,首先需要在maven的pom.xml中添加Ureport2的依赖。

        <!-- https://mvnrepository.com/artifact/com.bstek.ureport/ureport2-console -->
        <dependency>
            <groupId>com.bstek.ureport</groupId>
            <artifactId>ureport2-console</artifactId>
            <version>2.2.9</version>
        </dependency>

2.链接数据库的相关依赖(MySQL)。

         <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

3.在src/main/resources目录下的appliction.propertion中添加mysql数据库链接。

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/database?useSSL=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456

4.在src/main/resources目录下的appliction.propertion中添加Ureport2报表的存储路径配置。

## 更改 ureport2 的保存目录(需真实存在的目录)

# ureport.fileStoreDir=G:/tool/ureportfiles

##

## 如若不需要更改:

## 1.web项目:默认在项目web\web-inf\ureportfiles下

## 2.spring boot项目:

##   C:\Users\用户名\AppData\Local\Temp\tomcat-docbase.??.8080\WEB-INF\ureportfiles 下

5.在src/main/resources 下创建 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-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>

6.在Spring boot主类Application.java 添加注解和注册servlet。

package com.example.dppcpreportureport;

import com.bstek.ureport.console.UReportServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

/**

 * 加载对应的xml配置文件

 */

@ImportResource("classpath:context.xml")
@SpringBootApplication
public class DppcpReportUreportApplication {

    public static void main(String[] args) {
        SpringApplication.run(DppcpReportUreportApplication.class, args);
    }

    /**

     * 进行注册Servlet

     * 配置 UReport2 需要使用到的servlet

     */

    @Bean
    public ServletRegistrationBean buildUReportServlet() {

        /**

         * @param  servlet

         * @param  urlMappings 值为“/ureport/*”的 urlMappings 是一定不能变的,否则系统将无法运行。

         */

        return new ServletRegistrationBean(new UReportServlet(), "/ureport/*");

    }
}

7.运行启动Spring boot项目在浏览器输入:

http://localhost:8080/ureport/designer

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值