ApiTable 实现增删改查
本节介绍使用 tio-boot 整合 ApiTable 实现一个增删改查的小案例
创建表和插入数据
创建表
CREATE TABLE `system_users` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户账号',
`password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '密码',
`nickname` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户昵称',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '备注',
`dept_id` bigint DEFAULT NULL COMMENT '部门ID',
`post_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '岗位编号数组',
`email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '用户邮箱',
`mobile` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '手机号码',
`sex` tinyint DEFAULT '0' COMMENT '用户性别',
`avatar` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '头像地址',
`status` tinyint NOT NULL DEFAULT '0' COMMENT '帐号状态(0正常 1停用)',
`login_ip` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '最后登录IP',
`login_date` datetime DEFAULT NULL COMMENT '最后登录时间',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `idx_username` (`username`,`update_time`,`tenant_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=126 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户信息表';
插入一些测试数据
INSERT INTO `system_users` VALUES (1, 'admin', '$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm', '乒乒', '管理员', 103, '[1]', 'aoteman@126.com', '15612345678', 1, 'http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png', 0, '127.0.0.1', '2023-11-30 09:16:00', 'admin', '2021-01-05 17:03:47', NULL, '2024-03-23 08:49:55', b'0', 1);
INSERT INTO `system_users` VALUES (100, 'yudao', '$2a$10$11U48RhyJ5pSBYWSn12AD./ld671.ycSzJHbyrtpeoMeYiw31eo8a', 'TongLI', '不要吓我', 104, '[1]', 'yudao@iocoder.cn', '15601691300', 1, '', 1, '127.0.0.1', '2022-07-09 23:03:33', '', '2021-01-07 09:07:17', NULL, '2024-03-23 08:50:02', b'0', 1);
INSERT INTO `system_users` VALUES (103, 'yuanma', '$2a$10$YMpimV4T6BtDhIaA8jSW.u8UTGBeGhc/qwXP4oxoMr4mOw9.qttt6', '源码', NULL, 106, NULL, 'yuanma@iocoder.cn', '15601701300', 0, '', 0, '127.0.0.1', '2022-07-08 01:26:27', '', '2021-01-13 23:50:35', NULL, '2022-07-08 01:26:27', b'0', 1);
INSERT INTO `system_users` VALUES (104, 'test', '$2a$10$GP8zvqHB//TekuzYZSBYAuBQJiNq1.fxQVDYJ.uBCOnWCtDVKE4H6', '测试号', NULL, 107, '[1,2]', '111@qq.com', '15601691200', 1, '', 0, '0:0:0:0:0:0:0:1', '2023-09-24 18:21:19', '', '2021-01-21 02:13:53', NULL, '2023-09-24 18:21:19', b'0', 1);
INSERT INTO `system_users` VALUES (107, 'admin107', '$2a$10$dYOOBKMO93v/.ReCqzyFg.o67Tqk.bbc2bhrpyBGkIw9aypCtr2pm', 'admin', NULL, NULL, NULL, '', '15601691300', 0, '', 0, '', NULL, '1', '2022-02-20 22:59:33', '1', '2024-03-23 08:50:10', b'0', 118);
INSERT INTO `system_users` VALUES (108, 'admin108', '$2a$10$y6mfvKoNYL1GXWak8nYwVOH.kCWqjactkzdoIDgiKl93WN3Ejg.Lu', 'Nike', NULL, NULL, NULL, '', '15601691300', 0, '', 0, '', NULL, '1', '2022-02-20 23:00:50', '1', '2024-03-23 08:50:15', b'0', 119);
INSERT INTO `system_users` VALUES (109, 'admin109', '$2a$10$JAqvH0tEc0I7dfDVBI7zyuB4E3j.uH6daIjV53.vUS6PknFkDJkuK', 'Mike', NULL, NULL, NULL, '', '15601691300', 0, '', 0, '', NULL, '1', '2022-02-20 23:11:50', '1', '2024-03-23 08:50:23', b'0', 120);
INSERT INTO `system_users` VALUES (110, 'admin110', '$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm', '小王', NULL, NULL, NULL, '', '15601691300', 0, '', 0, '127.0.0.1', '2022-09-25 22:47:33', '1', '2022-02-22 00:56:14', NULL, '2022-09-25 22:47:33', b'0', 121);
INSERT INTO `system_users` VALUES (111, 'test', '$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm', '测试用户', NULL, NULL, '[]', '', '', 0, '', 0, '0:0:0:0:0:0:0:1', '2023-10-18 23:31:51', '110', '2022-02-23 13:14:33', NULL, '2023-10-18 23:31:51', b'0', 121);
INSERT INTO `system_users` VALUES (112, 'newobject', '$2a$10$3alwklxqfq8/hKoW6oUV0OJp0IdQpBDauLy4633SpUjrRsStl6kMa', '新对象', NULL, 100, '[]', '', '', 1, '', 0, '0:0:0:0:0:0:0:1', '2023-02-10 13:48:13', '1', '2022-02-23 19:08:03', NULL, '2023-02-10 13:48:13', b'0', 1);
INSERT INTO `system_users` VALUES (113, 'aoteman', '$2a$10$0acJOIk2D25/oC87nyclE..0lzeu9DtQ/n3geP4fkun/zIVRhHJIO', 'Bolbi', NULL, NULL, NULL, '', '15601691300', 0, '', 0, '127.0.0.1', '2022-03-19 18:38:51', '1', '2022-03-07 21:37:58', NULL, '2024-03-23 08:50:27', b'0', 122);
INSERT INTO `system_users` VALUES (114, 'hrmgr', '$2a$10$TR4eybBioGRhBmDBWkqWLO6NIh3mzYa8KBKDDB5woiGYFVlRAi.fu', 'hr 小姐姐', NULL, NULL, '[3]', '', '', 0, '', 0, '127.0.0.1', '2022-03-19 22:15:43', '1', '2022-03-19 21:50:58', NULL, '2022-03-19 22:15:43', b'0', 1);
INSERT INTO `system_users` VALUES (115, 'aotemane', '$2a$10$/WCwGHu1eq0wOVDd/u8HweJ0gJCHyLS6T7ndCqI8UXZAQom1etk2e', '1', '11', 101, '[]', '', '', 1, '', 0, '', NULL, '1', '2022-04-30 02:55:43', '1', '2022-06-22 13:34:58', b'0', 1);
INSERT INTO `system_users` VALUES (116, '15601691302', '$2a$10$L5C4S0U6adBWMvFv1Wwl4.DI/NwYS3WIfLj5Q.Naqr5II8CmqsDZ6', '小豆', NULL, NULL, NULL, '', '', 0, '', 0, '', NULL, '1', '2022-05-17 10:07:10', '1', '2022-05-17 10:07:10', b'0', 124);
INSERT INTO `system_users` VALUES (117, 'admin123', '$2a$10$WI8Gg/lpZQIrOEZMHqka7OdFaD4Nx.B/qY8ZGTTUKrOJwaHFqibaC', '测试号', '1111', 100, '[2]', '', '15601691234', 1, '', 0, '', NULL, '1', '2022-07-09 17:40:26', '1', '2022-07-09 17:40:26', b'0', 1);
INSERT INTO `system_users` VALUES (118, 'goudan', '$2a$10$Lrb71muL.s5/AFjQ2IHkzOFlAFwUToH.zQL7bnghvTDt/QptjGgF6', '狗蛋', NULL, 103, '[1]', '', '', 2, '', 0, '', NULL, '1', '2022-07-09 17:44:43', '1', '2023-11-18 19:02:13', b'0', 1);
添加依赖
用到的一些 jar 包可能已经比较旧了,请更新到最新版本
<dependencies>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>com.litongjava</groupId>
<artifactId>tio-boot</artifactId>
<version>${tio.boot.version}</version>
</dependency>
<dependency>
<groupId>com.litongjava</groupId>
<artifactId>api-table</artifactId>
<version>${tio.boot.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.10</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
</dependencies>
添加工具类
ApiTableController
package com.litongjava.tio.boot.table.to.json.controller;
import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.jfinal.kit.Kv;
import com.litongjava.annotation.EnableCORS;
import com.litongjava.annotation.RequestPath;
import com.litongjava.db.TableInput;
import com.litongjava.db.TableResult;
import com.litongjava.db.activerecord.Db;
import com.litongjava.db.activerecord.Record;
import com.litongjava.model.body.RespBodyVo;
import com.litongjava.model.page.DbPage;
import com.litongjava.model.page.Page;
import com.litongjava.table.services.ApiTable;
import com.litongjava.table.utils.EasyExcelResponseUtils;
import com.litongjava.table.utils.TableInputUtils;
import com.litongjava.table.utils.TableResultUtils;
import com.litongjava.tio.boot.http.TioRequestContext;
import com.litongjava.tio.boot.utils.TioRequestParamUtils;
import com.litongjava.tio.http.common.HttpRequest;
import com.litongjava.tio.http.common.HttpResponse;
import lombok.extern.slf4j.Slf4j;
@RequestPath("/api/table")
@Slf4j
@EnableCORS
public class ApiTableController {
@RequestPath("/index")
public String index() {
return "TableJsonController";
}
@RequestPath("/{f}/create")
public RespBodyVo create(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<Kv> dbJsonBean = ApiTable.saveOrUpdate(f, kv);
if (dbJsonBean.getCode() == 1) {
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
} else {
return RespBodyVo.fail(dbJsonBean.getMsg()).code(dbJsonBean.getCode()).data(dbJsonBean.getData());
}
}
@RequestPath("/{f}/list")
public RespBodyVo list(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<List<Record>> list = ApiTable.list(f, kv);
TableResult<List<Kv>> dbJsonBean = TableResultUtils.recordsToKv(list, false);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/listAll")
public RespBodyVo listAll(String f) {
log.info("tableName:{}", f);
TableResult<List<Record>> listAll = ApiTable.listAll(f);
TableResult<List<Kv>> dbJsonBean = TableResultUtils.recordsToKv(listAll, false);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/page")
public RespBodyVo page(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
Object current = map.remove("current");
if (current != null) {
// add support for ant design pro table
map.put("pageNo", current);
}
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<Page<Record>> page = ApiTable.page(f, kv);
TableResult<DbPage<Kv>> dbJsonBean = TableResultUtils.pageToDbPage(page, false);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/get")
public RespBodyVo get(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<Record> jsonBean = ApiTable.get(f, kv);
TableResult<Kv> dbJsonBean = TableResultUtils.recordToKv(jsonBean);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/update")
public RespBodyVo update(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<Kv> dbJsonBean = ApiTable.saveOrUpdate(f, kv);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/batchUpdate")
public RespBodyVo batchUpdate(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<Kv> dbJsonBean = ApiTable.batchUpdateByIds(f, kv);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/remove/{id}")
public RespBodyVo remove(String f, String id) {
log.info("tableName:{},id:{}", f, id);
TableResult<Boolean> dbJsonBean = ApiTable.updateFlagById(f, id, "deleted", 1);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/delete/{id}")
public RespBodyVo delete(String f, String id) {
log.info("tableName:{},id:{}", f, id);
TableResult<Boolean> dbJsonBean = ApiTable.delById(f, id);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/total")
public RespBodyVo total(String f) {
log.info("tableName:{},id:{}", f);
Long count = Db.count(f);
return RespBodyVo.ok(count);
}
/**
* 导出当前数据
*/
@RequestPath("/{f}/export-excel")
public HttpResponse exportExcel(String f, HttpRequest request) throws IOException {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
Object current = map.remove("current");
if (current != null) {
// add support for ant design pro table
map.put("pageNo", current);
}
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
String filename = f + "_export_" + System.currentTimeMillis() + ".xlsx";
// 获取数据
List<Record> records = ApiTable.list(f, kv).getData();
HttpResponse response = TioRequestContext.getResponse();
return EasyExcelResponseUtils.exportRecords(response, filename, f, records);
}
/**
* 导出所有数据
*/
@RequestPath("/{f}/export-table-excel")
public HttpResponse exportAllExcel(String f, HttpRequest request) throws IOException, SQLException {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
map.remove("current");
map.remove("pageNo");
map.remove("pageSize");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
// 导出 Excel
String filename = f + "-all_" + System.currentTimeMillis() + ".xlsx";
// 获取数据
List<Record> records = ApiTable.listAll(f, kv).getData();
HttpResponse response = TioRequestContext.getResponse();
EasyExcelResponseUtils.exportRecords(response, filename, f, records);
log.info("finished");
return response;
}
@RequestPath("/export-all-table-excel")
public HttpResponse exportAllTableExcel(HttpRequest request) throws IOException {
String filename = "all-table_" + System.currentTimeMillis() + ".xlsx";
String[] tables = ApiTable.getAllTableNames();
LinkedHashMap<String, List<Record>> allTableData = new LinkedHashMap<>();
for (String table : tables) {
// 获取数据
List<Record> records = ApiTable.listAll(table).getData();
allTableData.put(table, records);
}
HttpResponse response = TioRequestContext.getResponse();
EasyExcelResponseUtils.exportAllTableRecords(response, filename, allTableData);
log.info("finished");
return response;
}
@RequestPath("/{f}/pageDeleted")
public RespBodyVo pageDeleted(String f, HttpRequest request) {
Map<String, Object> map = TioRequestParamUtils.getRequestMap(request);
map.remove("f");
ApiTable.transformType(f, map);
TableInput kv = TableInputUtils.camelToUnderscore(map);
log.info("tableName:{},kv:{}", f, kv);
TableResult<DbPage<Kv>> dbJsonBean = TableResultUtils.pageToDbPage(ApiTable.page(f, kv), false);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/recover")
public RespBodyVo recover(String f, String id) {
log.info("tableName:{},id:{}", f, id);
TableResult<Boolean> dbJsonBean = ApiTable.updateFlagById(f, id, "deleted", 0);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/names")
public RespBodyVo tableNames() throws IOException {
String[] data = ApiTable.tableNames().getData();
return RespBodyVo.ok(data);
}
@RequestPath("/{f}/config")
public RespBodyVo fConfig(String f, String lang) {
log.info("tableName:{}", f);
TableResult<Map<String, Object>> dbJsonBean = ApiTable.tableConfig(f, f, lang);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
@RequestPath("/{f}/columns")
public RespBodyVo proTableColumns(String f) {
TableResult<List<Map<String, Object>>> dbJsonBean = ApiTable.columns(f);
return RespBodyVo.ok(dbJsonBean.getData()).code(dbJsonBean.getCode()).msg(dbJsonBean.getMsg());
}
}
测试 Controller
测试 list
- 查询条数据
- url:http://localhost:10051/table/system_users/list
- response
{
"data":
[
{
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"updateTime": "2024-03-23 08:49:55",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": null,
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": false,
"createTime": "2021-01-05 17:03:47",
"postIds": "[1]",
"loginIp": "127.0.0.1",
"nickname": "乒乒",
"tenantId": "1",
"id": "1",
"email": "aoteman@126.com",
"username": "admin",
"status": 0
},
....
],
"msg": null,
"code": 1,
"ok": true
}
create
- 添加一条数据
- url: http://localhost:10051/table/system_users/create
- request body
{
"username": "test01",
"nickname": "Test01",
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": null,
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": false,
"postIds": "[1]",
"loginIp": "127.0.0.1",
"tenantId": "1",
"email": "aoteman@126.com",
"status": 0
}
- response
{
"data": {
"id": "361177594135064576
},
"code": 1,
"msg": null,
"ok": true
}
- 插入到数据库中的数据
id username password nickname remark dept_id post_ids email mobile sex avatar status login_ip login_date creator create_time updater update_time deleted tenant_id
361177594135064576 test01 $2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm Test01 管理员 103 [1] aoteman@126.com 15612345678 1 http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png 0 127.0.0.1 2023-11-30 09:16:00 admin 2024-03-23 09:51:11 2024-03-23 09:51:11 0 1
listAll
- 查询所有数据
- url:http://localhost:10051/table/system_users/listAll
- response
{
"data": [
{
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"updateTime": "2024-03-23 09:51:11",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": "",
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": false,
"createTime": "2024-03-23 09:51:11",
"postIds": "[1]",
"loginIp": "127.0.0.1",
"nickname": "Test01",
"tenantId": "1",
"id": "361177594135064576",
"email": "aoteman@126.com",
"username": "test01",
"status": 0
}
],
"code": 1,
"msg": null,
"ok": true
}
page
- 分页查询
- url:http://localhost:10051/table/system_users/page
- response
{
"data":{
"total": 17,
"list":[
{
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"updateTime": "2024-03-23 08:49:55",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": null,
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": false,
"createTime": "2021-01-05 17:03:47",
"postIds": "[1]",
"loginIp": "127.0.0.1",
"nickname": "乒乒",
"tenantId": "1",
"id": "1",
"email": "aoteman@126.com",
"username": "admin",
"status": 0
},
...
]
},
"code": 1,
"msg": null,
"ok": true
}
get
- 查询一条数据
- url:http://localhost:10051/table/system_users/get?username=admin
- response
{
"data": {
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"updateTime": "2024-03-23 08:49:55",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": null,
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": false,
"createTime": "2021-01-05 17:03:47",
"postIds": "[1]",
"loginIp": "127.0.0.1",
"nickname": "乒乒",
"tenantId": "1",
"id": "1",
"email": "aoteman@126.com",
"username": "admin",
"status": 0
},
"code": 1,
"msg": null,
"ok": true
}
update
- 根据 ID 数据
- url:http://localhost:10051/table/system_users/update?id=1&nickname=%E4%B9%92%E4%B9%92%E7%A7%91%E6%8A%80
- response
{
"data": null,
"code": 1,
"msg": null,
"ok": true
}
delete
- 逻辑删除数据
- url:http://localhost:10051/table/system_users/delete?id=1
- response:
{
"data": null,
"code": 1,
"msg": null,
"ok": true
}
export-excel
- 导出 Excel,支持查询参数,不包含已经删除的数据
- url:http://localhost:10051/table/system_users/export-excel
- 下载 xlsx 文件
export-table-excel
- 返回所有数据,保护已经逻辑删除的数据
- http://localhost:10051/table/system_users/export-table-excel
- 下载 xlsx 文件
export-all-table-excel
- 数据库中所有表的数据,慎用
- http://localhost:10051/table/export-all-table-excel
- 下载 xlsx 文件
pageDeleted
- 分页查询已经逻辑删除的数据
- http://localhost:10051/table/system_users/pageDeleted
- response
{
"data": {
"total": 1,
"list": [
{
"creator": "admin",
"sex": 1,
"deptId": "103",
"mobile": "15612345678",
"loginDate": "2023-11-30 09:16:00",
"remark": "管理员",
"updateTime": "2024-03-23 10:13:25",
"avatar": "http://127.0.0.1:48080/admin-api/infra/file/4/get/37e56010ecbee472cdd821ac4b608e151e62a74d9633f15d085aee026eedeb60.png",
"updater": null,
"password": "$2a$10$mRMIYLDtRHlf6.9ipiqH1.Z.bh/R9dO9d5iHiGYPigi6r5KOoR2Wm",
"deleted": true,
"createTime": "2021-01-05 17:03:47",
"postIds": "[1]",
"loginIp": "127.0.0.1",
"nickname": "乒乒科技",
"tenantId": "1",
"id": "1",
"email": "aoteman@126.com",
"username": "admin",
"status": 0
}
]
},
"msg": null,
"code": 1,
"ok": true
}
recover
- 恢复已经逻辑删除的数据
- http://localhost:10051/table/system_users/recover?id=1
- response
{
"data": null,
"msg": null,
"code": 1,
"ok": true
}
names
- 获取数据库中所有表名
- http://localhost:10051/table/names
- response
{
"data":
[
"system_users"
...
],
"code": 1,
"msg": null,
"ok": true
}
columns
- 获取数据表的字段信息
- http://localhost:10051/table/system_users/config
- response
{
"code": 1,
"data": [
{
"title": "Id",
"dataIndex": "id",
"valueType": "text"
},
{
"title": "Username",
"dataIndex": "username",
"valueType": "text"
},
{
"title": "Password",
"dataIndex": "password",
"valueType": "text"
},
{
"title": "Nickname",
"dataIndex": "nickname",
"valueType": "text"
},
{
"title": "Signature",
"dataIndex": "signature",
"valueType": "text"
},
{
"title": "Title",
"dataIndex": "title",
"valueType": "text"
},
{
"title": "Group Name",
"dataIndex": "group_name",
"valueType": "text"
},
{
"title": "Tags",
"dataIndex": "tags",
"valueType": "text"
},
{
"title": "Notify Count",
"dataIndex": "notify_count",
"valueType": "text"
},
{
"title": "Unread Count",
"dataIndex": "unread_count",
"valueType": "text"
},
{
"title": "Country",
"dataIndex": "country",
"valueType": "text"
},
{
"title": "Access",
"dataIndex": "access",
"valueType": "text"
},
{
"title": "Geographic",
"dataIndex": "geographic",
"valueType": "text"
},
{
"title": "Address",
"dataIndex": "address",
"valueType": "text"
},
{
"title": "Remark",
"dataIndex": "remark",
"valueType": "text"
},
{
"title": "Dept Id",
"dataIndex": "dept_id",
"valueType": "text"
},
{
"title": "Post Ids",
"dataIndex": "post_ids",
"valueType": "text"
},
{
"title": "Email",
"dataIndex": "email",
"valueType": "text"
},
{
"title": "Phone",
"dataIndex": "phone",
"valueType": "text"
},
{
"title": "Sex",
"dataIndex": "sex",
"valueType": "text"
},
{
"title": "Avatar",
"dataIndex": "avatar",
"valueType": "text"
},
{
"title": "Status",
"dataIndex": "status",
"valueType": "text"
},
{
"title": "Login Ip",
"dataIndex": "login_ip",
"valueType": "text"
},
{
"title": "Login Date",
"dataIndex": "login_date",
"valueType": "datetime"
},
{
"title": "Creator",
"dataIndex": "creator",
"valueType": "text"
},
{
"title": "Create Time",
"dataIndex": "create_time",
"valueType": "datetime"
},
{
"title": "Updater",
"dataIndex": "updater",
"valueType": "text"
},
{
"title": "Update Time",
"dataIndex": "update_time",
"valueType": "datetime"
},
{
"title": "Deleted",
"dataIndex": "deleted",
"valueType": "text"
},
{
"title": "Tenant Id",
"dataIndex": "tenant_id",
"valueType": "text"
}
],
"ok": true
}