MySQL动态表单设计

表结构示意

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
DROP TABLE IF EXISTS `form`;
CREATE TABLE `form` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`owner_id` bigint DEFAULT 0 COMMENT '所属者, 关联到账号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '表单信息';


DROP TABLE IF EXISTS `form_field`;
CREATE TABLE `form_field` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`form_id` BIGINT DEFAULT 0 COMMENT '表单id',
`field_id` BIGINT DEFAULT 0 COMMENT '字段id',
`field_label` VARCHAR(50) DEFAULT NULL COMMENT '字段名字(用来显示,如姓名,性别)',
`place_holder` VARCHAR(50) DEFAULT NULL COMMENT '预期值提示信息',
`required` int DEFAULT 0 COMMENT '是否必填 0 否 1 是',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '表单配置';

DROP TABLE IF EXISTS `option`;
CREATE TABLE `option` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`form_field_id` BIGINT DEFAULT 0 COMMENT '表单字段id',
`value` BIGINT DEFAULT 0 COMMENT '下拉项配置',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '下拉项';

DROP TABLE IF EXISTS `field`;
CREATE TABLE `field` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`label` VARCHAR(50) DEFAULT NULL COMMENT '字段名(如单行输入框、单选框)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '基础字段';

DROP TABLE IF EXISTS `form_data`;
CREATE TABLE `form_data` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`form_field_id` BIGINT DEFAULT 0 COMMENT '表单字段id',
`value` VARCHAR(255) DEFAULT NULL COMMENT '表单字段数据',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '表单数据';

图解

该图示来源于idea中Database, 右击 Diagrams

最后

本文到此结束,感谢阅读。如果您觉得不错,请关注公众号【当我遇上你】,您的支持是我写作的最大动力。