由于本人使用的idea,所以接下來全程使用idea
1. 前期準備
先clone一份原始碼到本地, git下載地址 https://gitee.com/youseries/ureport.git
下載的原始碼檔案格式如下:

2. 匯入js專案
idea匯入js專案, ureport2-js 檔案, 如下:
匯入進來后是沒有node_modules檔案的
需要使用npm install 下載包,

- 修改Ureport2-js專案的package.json檔案
- 在scripts中添加 build及start
- 在devDependencies中添加webpack及webpack-cli、webpack-dev-server
- 在dependencies 中添加react及react-dom
"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檔案中的這句話

3. 匯入后端專案
1. 新建一個SpringBoot專案,
2. 如下步驟所示, 匯入Ureport其他四個專案,匯入Maven格式

- 依次匯入Ureport2-console、Ureport2-core、Ureport2-font、Ureport2-parent,

- 修改SpringBoot中的POM檔案,引入Ureport依賴
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-console</artifactId>
<version>2.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-core</artifactId>
<version>2.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.bstek.ureport</groupId>
<artifactId>ureport2-font</artifactId>
<version>2.0.1</version>
</dependency>
<!--我使用的oracle驅動, 如果你使用的mysql,那么自己換成你需要的版本-->
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</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
- 新建Ureport配置類,在SpringBoot包中創建config包
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;
}
}
- SpringBoot 啟動類如下:
- 啟動后控制臺會輸出路徑,可以訪問了,
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" +
"----------------------------------------------------------");
}
游覽器輸入路徑即可啟動完成,

!!!!歡迎討論,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/296613.html
標籤:其他
上一篇:七天學會NodeJS(四)一邊讀取一邊輸出回應、守護行程(child process、spawn)、功能-性能-穩定性-代碼部署
