当前位置: 首页 > news >正文

Dataway 让 Spring Boot 不再需要 Controller、Service、DAO、Mapper 简单接口直接开发。

新的sql语法可以先看一下官网,部署起来之后会用到Dataql:

DataQL - 数据查询语言https://www.dataql.net/先看一下效果

 接下来来实现一下。


1 创建spring boot项目  导入依赖

<!--begin dataWay--><!--hasor-spring 负责 Spring 和 Hasor 框架之间的整合--><dependency><groupId>net.hasor</groupId><artifactId>hasor-spring</artifactId><version>4.1.3</version></dependency><!--hasor-dataway 是工作在 Hasor 之上,利用 hasor-spring 我们就可以使用 dataway了。--><dependency><groupId>net.hasor</groupId><artifactId>hasor-dataway</artifactId><version>4.1.3-fix20200414</version><!-- 4.1.3 包存在UI资源缺失问题 --></dependency><!--end dataWay--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.15</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.10</version></dependency>

2.配置文件,安排数据源和ui界面配置,这里ui和swagger差不多。

 我这里没有用yml ,下面的几条配置可能会带有黄色下划线不用纠结

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=1
spring.datasource.druid.initial-size=3
spring.datasource.druid.max-active=10
spring.datasource.druid.max-wait=60000
spring.datasource.druid.min-idle=3
spring.datasource.druid.stat-view-servlet.login-password=admin
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.password=root
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3310/test?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username=root# 启用 Dataway 功能(默认不启用)
HASOR_DATAQL_DATAWAY=true
# 开启 ui 管理功能(注意生产环境必须要设置为 false,否则会造成严重的生产安全事故)
HASOR_DATAQL_DATAWAY_ADMIN=true# (可选)API工作路径
HASOR_DATAQL_DATAWAY_API_URL=/api/
# (可选)ui 的工作路径,只有开启 ui 管理功能后才有效
HASOR_DATAQL_DATAWAY_UI_URL=/interface-ui/

 3spring boot开启功能

在启动类上面添加注解

@EnableHasor()    // 在Spring 中启用 Hasor
@EnableHasorWeb() // 将 hasor-web 配置到 Spring 环境中,Dataway 的 UI 是通过 hasor-web 提供服务。

 4,在你连接的数据库添加两个表,这两个表来放你的api地址

建表语句如下

CREATE TABLE `interface_info` (`api_id`          int(11)      NOT NULL AUTO_INCREMENT   COMMENT 'ID',`api_method`      varchar(12)  NOT NULL                  COMMENT 'HttpMethod:GET、PUT、POST',`api_path`        varchar(512) NOT NULL                  COMMENT '拦截路径',`api_status`      int(2)       NOT NULL                  COMMENT '状态:0草稿,1发布,2有变更,3禁用',`api_comment`     varchar(255)     NULL                  COMMENT '注释',`api_type`        varchar(24)  NOT NULL                  COMMENT '脚本类型:SQL、DataQL',`api_script`      mediumtext   NOT NULL                  COMMENT '查询脚本:xxxxxxx',`api_schema`      mediumtext       NULL                  COMMENT '接口的请求/响应数据结构',`api_sample`      mediumtext       NULL                  COMMENT '请求/响应/请求头样本数据',`api_option`      mediumtext       NULL                  COMMENT '扩展配置信息',`api_create_time` datetime     DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',`api_gmt_time`    datetime     DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',PRIMARY KEY (`api_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway 中的API';CREATE TABLE `interface_release` (`pub_id`          int(11)      NOT NULL AUTO_INCREMENT   COMMENT 'Publish ID',`pub_api_id`      int(11)      NOT NULL                  COMMENT '所属API ID',`pub_method`      varchar(12)  NOT NULL                  COMMENT 'HttpMethod:GET、PUT、POST',`pub_path`        varchar(512) NOT NULL                  COMMENT '拦截路径',`pub_status`      int(2)       NOT NULL                  COMMENT '状态:0有效,1无效(可能被下线)',`pub_type`        varchar(24)  NOT NULL                  COMMENT '脚本类型:SQL、DataQL',`pub_script`      mediumtext   NOT NULL                  COMMENT '查询脚本:xxxxxxx',`pub_script_ori`  mediumtext   NOT NULL                  COMMENT '原始查询脚本,仅当类型为SQL时不同',`pub_schema`      mediumtext       NULL                  COMMENT '接口的请求/响应数据结构',`pub_sample`      mediumtext       NULL                  COMMENT '请求/响应/请求头样本数据',`pub_option`      mediumtext       NULL                  COMMENT '扩展配置信息',`pub_release_time`datetime     DEFAULT CURRENT_TIMESTAMP COMMENT '发布时间(下线不更新)',PRIMARY KEY (`pub_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COMMENT='Dataway API 发布历史。';create index idx_interface_release on interface_release (pub_api_id);

 5 创建一个类,将你的数据源个这个矿建,你的数据源现在是在springboot里面管理的。现在需要复制过来。如下

import net.hasor.core.ApiBinder;
import net.hasor.core.DimModule;
import net.hasor.db.JdbcModule;
import net.hasor.db.Level;
import net.hasor.spring.SpringModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import javax.sql.DataSource;@DimModule
@Component
public class DatawayModule implements SpringModule {@Autowiredprivate DataSource dataSource = null;@Overridepublic void loadModule(ApiBinder apiBinder) throws Throwable {// .DataSource form Spring boot into HasorapiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));}}

 6.启动项目不保错。显示如下就是成功。


 7访问你的web界面地址,跟我配置的如下

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


 8,这里可以写直接写sql,发布在你的服务上面。语法支持sql和dataql可以好好学习一下。

发布之后你可以访问一下,还有就是看看数据库

 

 


http://www.lryc.cn/news/23531.html

相关文章:

  • C#窗口介绍
  • SpringBoot:SpringBoot整合Junit 和 MyBatis(3)
  • Web自动化测试框架Selenium
  • 大数据系统自检
  • MySQL数据库操作
  • 线程安全实例分析
  • Tomcat源码分析-启动分析(二) Catalina初始化
  • 基础复习第二十二天 泛型的使用
  • 【C++进阶】三、二叉搜索树
  • 电脑系统崩溃怎么修复教程
  • 语义分割数据标注案例分析
  • 回归预测 | MATLAB实现GRU(门控循环单元)多输入单输出(多指标评价)
  • 驱动程序开发:Buildroot根文件系统构建并加载驱动文件xxx.ko测试
  • R+VIC模型融合实践技术应用及未来气候变化模型预测
  • 第六章.决策树(Decision Tree)—ID3算法,C4.5算法
  • springboot+pgbouncer+postgres数据库连接池集成方案及问题解决
  • Mysql 常用日期处理函数
  • Pod中容器的健康检查
  • 信贷系统学习总结(5)—— 简单的风控示例(含代码)
  • Java知识复习(四)多线程、并发编程
  • 一个9个月测试经验的人,居然在面试时跟我要18K,我都被他吓到了····
  • zigbee与WIFI同频干扰问题
  • git拉取指定的单个或多个文件或文件夹
  • 不是,到底有多少种图片懒加载方式?
  • CAD坐标有哪些输入方式?来看看这些CAD坐标输入方式!
  • 铰链、弹簧,特殊的物理关节
  • Android Studio相关记录
  • Linux 基础介绍-基础命令
  • Linux 进程:程序地址空间 与 虚拟内存
  • python 密码学编程