由于本人使用的idea,所以接下来全程使用idea
先clone一份源码到本地。 git下载地址 https://gitee.com/youseries/ureport.git
idea导入js项目, ureport2-js 文件。 如下:
导入进来后是没有node_modules文件的
需要使用npm install 下载包。
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"start": "webpack-dev-server --open"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.11",
"expose-loader": "^0.7.1",
"file-loader": "^0.9.0",
"style-loader": "^0.13.1",
"uglifyjs-webpack-plugin": "^1.2.4",
"url-loader": "^0.5.7",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.2"
},
"dependencies": {
"bootbox": "^4.4.0",
"bootstrap": "^3.3.7",
"bootstrap-colorpicker": "^2.5.0",
"chart.js": "^2.7.2",
"chartjs-plugin-datalabels": "^0.3.0",
"codemirror": "^5.23.0",
"completer": "^0.1.3",
"handsontable": "^0.32.0",
"jquery": "^3.1.1",
"jquery-contextmenu": "^2.4.2",
"node-uuid": "^1.4.7",
"raphael": "^2.2.7",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"save-svg-as-png": "^1.3.2",
"undo-manager": "^1.0.5"
}
以上js项目配置完成。
可以试一下npm run start启动,但是这个项目并不能直接启动, 如需修改的话,修改后可执行npm run build打包
打包后会在源码的Ureoirt2-console项目的src/main/resources/ureport-asserts/js下生成四个js文件。
分别为common.bundle.js、designer.bundle.js、preview.bundle.js、searchform.bundle.js
具体为什么可以参考js项目的webpack.config.js文件中的这句话
1. 新建一个SpringBoot项目。
2. 如下步骤所示, 导入Ureport其他四个项目。导入Maven格式
<dependency>
<groupId>com.bstek.ureportgroupId>
<artifactId>ureport2-consoleartifactId>
<version>2.3.0-SNAPSHOTversion>
dependency>
<dependency>
<groupId>com.bstek.ureportgroupId>
<artifactId>ureport2-coreartifactId>
<version>2.3.0-SNAPSHOTversion>
dependency>
<dependency>
<groupId>com.bstek.ureportgroupId>
<artifactId>ureport2-fontartifactId>
<version>2.0.1version>
dependency>
<dependency>
<groupId>com.oracle.ojdbcgroupId>
<artifactId>ojdbc8artifactId>
<version>19.3.0.0version>
dependency>
server:
port: 8066
tomcat:
max-swallow-size: -1
servlet:
context-path:
address: 0.0.0.0
spring:
datasource:
url: jdbc:mysql://192.168.999.999:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
ureport:
disableHttpSessionReportCache: false
#UReport2默认报表存储
disableFileProvider: false
fileStoreDir: D:/cshi
debug: true
package com.tiancai.master.config;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@Component
@Configuration
//不加项目能够启动但是会导致加载数据源报错或加载不了
@ImportResource("classpath:ureport-console-context.xml")
public class UreportDatasource implements BuildinDatasource {
private static final String NAME = "oracle";
private Logger log = LoggerFactory.getLogger(UreportDatasource.class);
@Autowired
private DataSource dataSource;
/**
* 配置ureport的servlet
* @return
*/
@Bean
public ServletRegistrationBean buildUReportServlet() {
//htreport
return new ServletRegistrationBean(new UReportServlet(),"/ureport/*");
}
/**
* ds1数据库配置
*/
@Bean("ds1")
@ConfigurationProperties(prefix = "spring.datasource.druid.ds1")
public DataSource ds1Source() {
return DataSourceBuilder.create().build();
}
@Override
public String name() {
return NAME;
}
@Override
public Connection getConnection() {
try {
return dataSource.getConnection();
} catch (SQLException e) {
log.error("Ureport 数据源 获取连接失败!");
e.printStackTrace();
}
return null;
}
}
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(MasterApplication.class, args);
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path")==null?"":env.getProperty("server.servlet.context-path");
System.out.println("\n----------------------------------------------------------\n\t" +
"Application UReport is running! Access URLs:\n\t" +
"Local: \t\thttp://localhost:" + port + path + "/ureport/designer\n\t" +
"----------------------------------------------------------");
}
!!!!欢迎讨论。