APIJSON 是一种专为 API 而生的 JSON 网络传输协议 以及 基于这套协议实现的 ORM 库。为简单的增删改查、复杂的查询、简单的事务操做 提供了彻底自动化的万能 API。能大幅下降开发和沟通成本,简化开发流程,缩短开发周期。适合中小型先后端分离的项目,尤为是 BaaS、Serverless、互联网创业项目和企业自用项目。html
Gitee:https://gitee.com/Tencent/APIJSONjava
Java端:https://gitee.com/greyzeng/apijson-samplegit
DemoSQLConfig.java这个文件中提供了数据库的配置信息github
须要配置:sql
将/sql目录下的脚本文件导入数据库中。数据库
将/libs目录下的jar包增长到项目的classpath中json
运行DemoApplication后端
在Postman中新增一个POST请求,请求的URL是:api
请求的Body是:
{ "Moment": { "id": 12 } }
返回的结果是:
{ "Moment": { "id": 12, "userId": 70793, "date": "2017-02-08 16:06:11.0", "content": "APIJSON,let interfaces and documents go to hell !", "praiseUserIdList": [ 70793, 93793, 82044, 82040, 82055, 90814, 38710, 82002, 82006, 1508072105320, 82001 ], "pictureList": [ "http://static.oschina.net/uploads/img/201604/22172508_eGDi.jpg", "http://static.oschina.net/uploads/img/201604/22172507_rrZ5.jpg", "https://camo.githubusercontent.com/788c0a7e11a4f5aadef3c886f028c79b4808613a/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343932353935372d313732303737333630382e6a7067", "http://static.oschina.net/uploads/img/201604/22172507_Pz9Y.png", "https://camo.githubusercontent.com/c98b1c86af136745cc4626c6ece830f76de9ee83/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343930383036362d313837323233393236352e6a7067", "https://camo.githubusercontent.com/f513fa631bd780dc0ec3cf2663777e356dc3664f/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343733323232332d3337333933303233322e6a7067", "https://camo.githubusercontent.com/c98b1c86af136745cc4626c6ece830f76de9ee83/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343930383036362d313837323233393236352e6a7067", "https://camo.githubusercontent.com/f513fa631bd780dc0ec3cf2663777e356dc3664f/687474703a2f2f696d61676573323031352e636e626c6f67732e636f6d2f626c6f672f3636303036372f3230313630342f3636303036372d32303136303431343232343733323232332d3337333933303233322e6a7067" ] }, "ok": true, "code": 200, "msg": "success", "sql:generate|cache|execute|maxExecute": "1|0|1|200", "depth:count|max": "1|5", "time:start|duration|end": "1611279884442|12|1611279884454" }
更多的接口功能和查询语法见:
需求:假设咱们须要新增一张数据表,并把数据表的数据快速发布出来
假设要增长的数据表以下:
-- 原石 CREATE TABLE `b_stone` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `cost` int(10) NULL COMMENT '成本', `price` int(10) NULL COMMENT '卖价', `length` int(10) NULL, `width` int(10) NULL, `height` int(10) NULL, `weight` float(8,1) NULL, `creationdate` datetime default CURRENT_TIMESTAMP COMMENT '建立时间', `modifydate` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间', `modifier` varchar(80) NULL, PRIMARY KEY (`id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8;
咱们须要在model包下增长一个类:
package apijson.demo.model; import apijson.MethodAccess; @MethodAccess( POST = {UNKNOWN, ADMIN}, DELETE = {ADMIN} ) public class Stone { }
在DemoSQLConfig中增长:
TABLE_KEY_MAP.put(Stone.class.getSimpleName(),"b_store");
配置表和实体类的映射
还须要在这个类中注册权限:
AbstractVerifier.ACCESS_MAP.put(Stone.class.getSimpleName(),getAccessMap(Stone.class.getAnnotation(MethodAccess.class)));
为了防止登陆错误,咱们能够提早先增长以下代码,DemoParser中,在每一个构造方法执行完super()后增长:
setNeedVerify(false);
重启应用,POST请求:http://localhost:8080/get
body
{ "Stone": { "id": 1 } }
返回
{ "Stone": { "id": 1, "cost": 2, "price": 3, "length": 4, "width": 5, "height": 6, "weight": 7.0, "creationdate": "2021-01-22 10:00:56.0", "modifydate": "2021-01-22 10:01:00.0", "modifier": "8" }, "ok": true, "code": 200, "msg": "success", "sql:generate|cache|execute|maxExecute": "1|0|1|200", "depth:count|max": "1|5", "time:start|duration|end": "1611282106759|10|1611282106769" }
接口的查询能够能够配置是否须要登陆,登陆接口:http://127.0.0.1:8080/login,
发送请求
{ "phone": "13000038710", "password": "apijson" }
帐号和密码,能够到apijson_user表里面查询