UReport2 生成 excel 文档确实很强大
入门《文档》
1. pom 文件引入 依赖
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-console</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.4</version>
</dependency>
</dependencies>
2. 添加 servlet 配置 UreportConfig.java
package com.min.demo.config;
import com.bstek.ureport.console.UReportServlet;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@ImportResource("classpath:ureport-console-context.xml")
@Configuration
public class UreportConfig implements BuildinDatasource {
@Resource
DataSource dataSource;
private Logger log = LoggerFactory.getLogger(getClass());
@Bean
public ServletRegistrationBean buildUreportServlet(){
return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
}
@Override
public String name() {
return "System";
}
@Override
public Connection getConnection() {
try {
return dataSource.getConnection();
} catch (SQLException e) {
log.error("Ureport 数据源 获取连接失败!");
e.printStackTrace();
}
return null;
}
}
3. ureport 默认配置 ureport.properties
ureport.disable**加粗样式**HttpSessionReportCache=false
#UReport2默认报表存储
ureport.disableFileProvider=false
ureport.fileStoreDir=d:/ureportfiles
ureport.debug=true
4. application.yml
spring:
application:
name: demo
main:
allow-bean-definition-overriding: true
datasource:
druid:
url: jdbc:mysql://localhost:3306/ier?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
initialSize: 10
minIdle: 10
maxActive: 100
maxWait: 3000
timeBetweenEvictionRunsMillis: 30000
minEvictableIdleTimeMillis: 30000
server:
port: 8090
5. 启动 访问 http://localhost:8090/ureport/designer
6. 目录结构