Getting Started with Spring Boot: Integrate Hasor's Dataway module, wipe out the background, and automatically configure interfaces

Finally out of Hubei, closed for 2 months, no computer at home, feel independently code Ah Ah Ah Ah Ah Ah Ah Ah Ah Ah.

Connect to previous article Getting Started with Spring Boot (12): Report Export, Comparing the Efficiency of poi, jxl, and esayExcel Continue from the beginning to the pit.

dataWay is just open source, you can go to the official website to see it https://www.hasor.net/web/overview/about.html , China's open source software, finally do not need to read Tadpole English.

1.dataWay has been donated to Apache and has been maintained by a reliable team that can be used with confidence

2.dataWay only supports JDK1.8 and above, currently only supports mysql and oracle databases

3.At present, it has developed to 4.1.4. Recently, I read some blogs, and a lot of people have reacted with some inadequacies.

 

1. Code

There are already many good blogs on the spring boot integrated Dataway website, official website https://www.hasor.net/web/dataway/for_boot.html Very detailed, I'll post the relevant code briefly

  • rely on
 1  <!--begin dataWay-->
 2         <!--hasor-spring Be responsible for Spring and Hasor Integration between frameworks-->
 3         <dependency>
 4             <groupId>net.hasor</groupId>
 5             <artifactId>hasor-spring</artifactId>
 6             <version>4.1.3</version>
 7         </dependency>
 8         <!--hasor-dataway Is working in Hasor Above, utilize hasor-spring We can use it dataway Yes.-->
 9         <dependency>
10             <groupId>net.hasor</groupId>
11             <artifactId>hasor-dataway</artifactId>
12             <version>4.1.3-fix20200414</version><!-- 4.1.3 Package Exists UI Missing resources -->
13         </dependency>
14         <!--end dataWay-->
  • yml Profile
 1 #dataway config
 2 # Whether the Dataway feature is enabled (required: default false)
 3 HASOR_DATAQL_DATAWAY: true
 4 # Whether to open the Dataway background management interface (required: default false)
 5 HASOR_DATAQL_DATAWAY_ADMIN: true
 6 # Dataway API working path (optional, default: /api/)
 7 HASOR_DATAQL_DATAWAY_API_URL: /api/
 8 # The working path of the dataway-ui (optional, default: /interface-ui/)
 9 HASOR_DATAQL_DATAWAY_UI_URL: /interface-ui/
10 # SQL Executor Dialect Settings (optional, recommended)
11 HASOR_DATAQL_FX_PAGE_DIALECT: mysql
  • New Class
 1 package com.learn.hello.system.common.hasor;
 2 
 3 import net.hasor.core.ApiBinder;
 4 import net.hasor.core.DimModule;
 5 import net.hasor.db.JdbcModule;
 6 import net.hasor.db.Level;
 7 import net.hasor.spring.SpringModule;
 8 import org.springframework.beans.factory.annotation.Autowired;
 9 import org.springframework.stereotype.Component;
10 
11 import javax.sql.DataSource;
12 
13 /**
14  * @ClassName DatawayModule
15  * @Deccription TODO
16  * @Author DZ
17  * @Date 2020/5/13 21:48
18  **/
19 @DimModule
20 @Component
21 public class DatawayModule implements SpringModule {
22     @Autowired
23     private DataSource dataSource = null;
24     @Override
25     public void loadModule(ApiBinder apiBinder) throws Throwable {
26         apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));
27     }
28 }
  • spring startup class opens hasor

 

  • sql table, you can refer to the official website, which provides mysql and oracle statements
 1 CREATE TABLE `interface_info` (
 2     `api_id`          int(11)      NOT NULL AUTO_INCREMENT   COMMENT 'ID',
 3     `api_method`      varchar(12)  NOT NULL                  COMMENT 'HttpMethod: GET,PUT,POST',
 4     `api_path`        varchar(512) NOT NULL                  COMMENT 'Intercept Path',
 5     `api_status`      int(2)       NOT NULL                  COMMENT 'Status: 0 draft, 1 release, 2 changes, 3 Disabled',
 6     `api_comment`     varchar(255)     NULL                  COMMENT 'Notes',
 7     `api_type`        varchar(24)  NOT NULL                  COMMENT 'Script type: SQL,DataQL',
 8     `api_script`      mediumtext   NOT NULL                  COMMENT 'Query script: xxxxxxx',
 9     `api_schema`      mediumtext       NULL                  COMMENT 'Request for interface/Response Data Structure',
10     `api_sample`      mediumtext       NULL                  COMMENT 'request/response/Request Header Sample Data',
11     `api_option`      mediumtext       NULL                  COMMENT 'Extended configuration information',
12     `api_create_time` datetime     DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation Time',
13     `api_gmt_time`    datetime     DEFAULT CURRENT_TIMESTAMP COMMENT 'Modification Time',
14     PRIMARY KEY (`api_id`)
15 ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway In API';
16 
17 CREATE TABLE `interface_release` (
18     `pub_id`          int(11)      NOT NULL AUTO_INCREMENT   COMMENT 'Publish ID',
19     `pub_api_id`      int(11)      NOT NULL                  COMMENT 'Ownership API ID',
20     `pub_method`      varchar(12)  NOT NULL                  COMMENT 'HttpMethod: GET,PUT,POST',
21     `pub_path`        varchar(512) NOT NULL                  COMMENT 'Intercept Path',
22     `pub_status`      int(2)       NOT NULL                  COMMENT 'Status: 0 valid, 1 invalid (may be offline)',
23     `pub_type`        varchar(24)  NOT NULL                  COMMENT 'Script type: SQL,DataQL',
24     `pub_script`      mediumtext   NOT NULL                  COMMENT 'Query script: xxxxxxx',
25     `pub_script_ori`  mediumtext   NOT NULL                  COMMENT 'The original query script, only if the type is SQL Different time',
26     `pub_schema`      mediumtext       NULL                  COMMENT 'Request for interface/Response Data Structure',
27     `pub_sample`      mediumtext       NULL                  COMMENT 'request/response/Request Header Sample Data',
28     `pub_option`      mediumtext       NULL                  COMMENT 'Extended configuration information',
29     `pub_release_time`datetime     DEFAULT CURRENT_TIMESTAMP COMMENT 'Release time (no updates offline)',
30     PRIMARY KEY (`pub_id`)
31 ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API Publish history.';
32 
33 create index idx_interface_release on interface_release (pub_api_id);

 

2. Start

According to the official website, a dataway log is required in the log to be started successfully, as follows

 

When I started, there were no relevant logs and I could use them normally. I don't know the specific reason yet, so I will discuss it later.Below is my boot log.After you start, you find that there are no logs to try whether dataway can be used (access the url of dataWay) first, and if it can be used properly, you can ignore the log problem first.

 

 

3. Configure interfaces

Access url: http://localhost:8080/interface-ui/#/

 

Here's a hole: executing sql returns Unknown SqlMode as shown in the figure

 

 

Because sql is not on the first line, a default comment is automatically generated on the first line. Delete the comment.Figure

 

Additionally, the access url of the dataWay needs to be filtered in the interceptor, otherwise it will be intercepted, making it accessible only when logged in.Note Security Configuration

Code passed to git: https://gitee.com/bald_dz/SpringbootLean

Tags: Java Spring SQL MySQL Oracle

Posted on Wed, 13 May 2020 11:00:31 -0700 by matt1