该项目提供基于orm框架activejdbc的功能扩展。
项目将在springboot项目启动时、遍历容器中的数据源。
然后自动扫描数据库中每一张表的元数据 包括表名、主键、字段名、字段类型等。
在这个基础上使用JavaAssist字节码生成框架 动态生成所有必要的字节码并注入到容器中。
最终 本项目会为数据库的每一张表提供一套通用的CRUD接口:
- 单条新增
- 单条修改
- 单条查询
- 单条删除
- 批量新增
- 批量修改
- 批量删除
- 分页查询
从而消除Java后端开发中重复性的简单接口开发工作。使后端开发者从重复性的开发任务中解放出来,专注与业务功能开发。
基于以上特性,该项目期望淘汰一些代码生成工具和插件。
2021-10-06 1.0 版本正式发布到中央仓库
<dependency>
<groupId>cn.ipfs-files</groupId>
<artifactId>activejdbc-spring-boot-starter</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
Base URLs:
GET /model/{model-name}
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| isEqual | query | string | 否 | 是否全等匹配,不填默认为false(true/false) |
| order | query | string | 否 | 分页参数-排序方式,与排序字段对应,多个以英文逗号隔开 |
| pageNum | query | string | 否 | 分页参数-当前页码 |
| pageSize | query | string | 否 | 分页参数-每页条数 |
| sort | query | string | 否 | 分页参数-排序字段名,对应表结构必须包含该字段,多个以英文逗号隔开 |
返回示例
200 Response
{
"code": 0,
"data": {
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{}
],
"total": 0
},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
PUT /model/{model-name}
Body 请求参数
"string"| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| body | body | string | 否 | none |
返回示例
200 Response
{
"code": 0,
"data": {},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 201 | Created | Created | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
POST /model/{model-name}
Body 请求参数
"string"| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| body | body | string | 否 | none |
返回示例
200 Response
{
"code": 0,
"data": {},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 201 | Created | Created | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
DELETE /model/{model-name}/array
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | none |
| id | query | integer | 是 | 对应主键id |
返回示例
200 Response
{
"code": 0,
"data": [
{
"compositeKeys": [
"string"
],
"frozen": true,
"id": {},
"idName": "string",
"longId": 0,
"modified": true,
"new": true,
"valid": true
}
],
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 204 | No Content | No Content | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
PUT /model/{model-name}/batchCreateOrUpdate
Body 请求参数
"string"| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| body | body | string | 否 | none |
返回示例
200 Response
{
"code": 0,
"data": [
{
"compositeKeys": [
"string"
],
"frozen": true,
"id": {},
"idName": "string",
"longId": 0,
"modified": true,
"new": true,
"valid": true
}
],
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 201 | Created | Created | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
POST /model/{model-name}/filter
Body 请求参数
{
"columns": [
"string"
],
"pageNum": 1,
"pageSize": 10,
"querys": [
[
{
"name": "id",
"operation": "EQUAL",
"value": "1"
}
]
],
"sorter": [
{
"direction": "ASC",
"property": "id"
}
],
"view": {}
}| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| body | body | any | 否 | none |
返回示例
200 Response
{
"code": 0,
"data": {
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{
"property1": {},
"property2": {}
}
],
"total": 0
},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 201 | Created | Created | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
GET /model/{model-name}/findFirst
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
返回示例
200 Response
{
"code": 0,
"data": {},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
GET /model/{model-name}/include
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| model-name | path | string | 是 | 表名 |
| isEqual | query | string | 否 | 是否全等匹配,不填默认为false(true/false) |
| order | query | string | 否 | 分页参数-排序方式,与排序字段对应,多个以英文逗号隔开 |
| pageNum | query | string | 否 | 分页参数-当前页码 |
| pageSize | query | string | 否 | 分页参数-每页条数 |
| sort | query | string | 否 | 分页参数-排序字段名,对应表结构必须包含该字段,多个以英文逗号隔开 |
返回示例
200 Response
{
"code": 0,
"data": {
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{}
],
"total": 0
},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
GET /model/{model-name}/{id}
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| id | path | integer | 是 | 对应主键id |
| model-name | path | string | 是 | 表名 |
返回示例
200 Response
{
"code": 0,
"data": {},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
| 404 | Not Found | Not Found | Inline |
DELETE /model/{model-name}/{id}
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| id | path | integer | 是 | 对应主键id |
| model-name | path | string | 是 | 表名 |
返回示例
200 Response
{
"code": 0,
"data": {},
"message": "string"
}| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | OK | Inline |
| 204 | No Content | No Content | Inline |
| 401 | Unauthorized | Unauthorized | Inline |
| 403 | Forbidden | Forbidden | Inline |
{
"code": 0,
"data": {
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{
"property1": {},
"property2": {}
}
],
"total": 0
},
"message": "string"
}
Response«PageQuery«Map«string,object»»»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| code | integer(int32) | false | none | none | |
| data | PageQuery«Map«string,object»» | false | none | none | |
| message | string | false | none | none |
{
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{
"property1": {},
"property2": {}
}
],
"total": 0
}
PageQuery«Map«string,object»»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| orderBys | string | false | none | none | |
| pageNum | integer(int32) | false | none | none | |
| pageSize | integer(int32) | false | none | none | |
| rows | [object] | false | none | none | |
| » additionalProperties | object | false | none | none | |
| total | integer(int64) | false | none | none |
{
"columns": [
"string"
],
"pageNum": 1,
"pageSize": 10,
"querys": [
[
{
"name": "id",
"operation": "EQUAL",
"value": "1"
}
]
],
"sorter": [
{
"direction": "ASC",
"property": "id"
}
],
"view": {}
}
QueryFilter«BaseModelVO»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| columns | [string] | false | none | 返回字段 | |
| pageNum | integer(int32) | false | none | 页号 | |
| pageSize | integer(int32) | false | none | 分页大小 | |
| querys | [array] | false | none | 查询条件组,各条件组之间以and链接 同一组条件之间以or链接 |
|
| sorter | [FieldSort] | false | none | 字段排序 | |
| view | BaseModelVO | false | none | 可作为查询参数的字段列表 |
{}
BaseModelVO
None
{
"direction": "ASC",
"property": "id"
}
FieldSort
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| direction | string | false | none | 排序方向 | |
| property | string | false | none | 排序字段 |
| 属性 | 值 |
|---|---|
| direction | ASC |
| direction | DESC |
{
"name": "id",
"operation": "EQUAL",
"value": "1"
}
QueryField
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| name | string | false | none | 当前表包含的字段名 | |
| operation | string | true | none | 比较符 [EQUAL,等于,=] [NOT_EQUAL: 不等于,!=] [LESS: 小于,<] [LESS_EQUAL: 小于等于,<=] [GREAT: 大于,>] [GREAT_EQUAL: 大于等于,>=] [LIKE: 包含,like] [NOT_LIKE: 不包含,not like] [LEFT_LIKE: 以...开始,like] [NOT_LEFT_LIKE: 不以...开始,not like] [RIGHT_LIKE: 以...结束,like] [NOT_RIGHT_LIKE: 不以...结束,not like] [IS_NULL: 为null,is null] [NOT_NULL: 不为null,is not null] [IS_EMPTY: 空字符串, == ''] [NOT_EMPTY: 非空字符串,!= ''] [IN: 在...中,in] [NOT_IN: 不在...中,not in] [BETWEEN: 在...之间,between] [NOT_BETWEEN: 不在...之间,not between] [EQUAL_IGNORE_CASE: 等于忽略大小写,=] [REGEXP: 正则表达式匹配,REGEXP] |
|
| value | object | false | none | 字段值: 数字,日期,字符串,数组 [1,2,3]/'value'/123/'2020-10-01' |
| 属性 | 值 |
|---|---|
| operation | BETWEEN |
| operation | EQUAL |
| operation | EQUAL_IGNORE_CASE |
| operation | GREAT |
| operation | GREAT_EQUAL |
| operation | IN |
| operation | IS_EMPTY |
| operation | IS_NULL |
| operation | LEFT_LIKE |
| operation | LESS |
| operation | LESS_EQUAL |
| operation | LIKE |
| operation | NOT_BETWEEN |
| operation | NOT_EMPTY |
| operation | NOT_EQUAL |
| operation | NOT_IN |
| operation | NOT_LEFT_LIKE |
| operation | NOT_LIKE |
| operation | NOT_NULL |
| operation | NOT_RIGHT_LIKE |
| operation | REGEXP |
| operation | RIGHT_LIKE |
{
"code": 0,
"data": [
{
"compositeKeys": [
"string"
],
"frozen": true,
"id": {},
"idName": "string",
"longId": 0,
"modified": true,
"new": true,
"valid": true
}
],
"message": "string"
}
Response«List«Model»»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| code | integer(int32) | false | none | none | |
| data | [Model] | false | none | none | |
| message | string | false | none | none |
{
"compositeKeys": [
"string"
],
"frozen": true,
"id": {},
"idName": "string",
"longId": 0,
"modified": true,
"new": true,
"valid": true
}
Model
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| compositeKeys | [string] | false | none | none | |
| frozen | boolean | false | none | none | |
| id | object | false | none | none | |
| idName | string | false | none | none | |
| longId | integer(int64) | false | none | none | |
| modified | boolean | false | none | none | |
| new | boolean | false | none | none | |
| valid | boolean | false | none | none |
{
"code": 0,
"data": {},
"message": "string"
}
Response«Map«string,object»»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| code | integer(int32) | false | none | none | |
| data | object | false | none | none | |
| message | string | false | none | none |
{
"code": 0,
"data": {
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{}
],
"total": 0
},
"message": "string"
}
Response«PageQuery»
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| code | integer(int32) | false | none | none | |
| data | PageQuery | false | none | none | |
| message | string | false | none | none |
{
"orderBys": "string",
"pageNum": 0,
"pageSize": 0,
"rows": [
{}
],
"total": 0
}
PageQuery
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| orderBys | string | false | none | none | |
| pageNum | integer(int32) | false | none | none | |
| pageSize | integer(int32) | false | none | none | |
| rows | [object] | false | none | none | |
| total | integer(int64) | false | none | none |