{"id":14972993,"url":"https://github.com/liyupi/sql-father-backend-public","last_synced_at":"2025-05-15T13:05:38.856Z","repository":{"id":61843450,"uuid":"554012697","full_name":"liyupi/sql-father-backend-public","owner":"liyupi","description":"新项目：快速生成 SQL 和模拟数据的网站（Java 后端），大幅提高开发测试效率！by 程序员鱼皮","archived":false,"fork":false,"pushed_at":"2023-05-21T12:06:46.000Z","size":77,"stargazers_count":2021,"open_issues_count":31,"forks_count":696,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-14T20:58:36.879Z","etag":null,"topics":["backend","database","freemarker","java","spring","springboot","sql"],"latest_commit_sha":null,"homepage":"http://sqlfather.yupi.icu","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liyupi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-19T05:33:48.000Z","updated_at":"2025-04-14T14:03:17.000Z","dependencies_parsed_at":"2024-12-27T23:30:10.685Z","dependency_job_id":"d6eb2eb2-48c6-4545-b234-1a3a06663bc2","html_url":"https://github.com/liyupi/sql-father-backend-public","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":"0.19999999999999996","last_synced_commit":"57a00afb82a9546385f7cb6fd60ae20f6db058f4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyupi%2Fsql-father-backend-public","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyupi%2Fsql-father-backend-public/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyupi%2Fsql-father-backend-public/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyupi%2Fsql-father-backend-public/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liyupi","download_url":"https://codeload.github.com/liyupi/sql-father-backend-public/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","database","freemarker","java","spring","springboot","sql"],"created_at":"2024-09-24T13:47:54.315Z","updated_at":"2025-05-15T13:05:38.774Z","avatar_url":"https://github.com/liyupi.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Father - 模拟数据生成器（后端）\n\n\u003e SQL 之父项目：快速生成 SQL 和模拟数据，大幅提高开发测试效率！\n\u003e\n\u003e 前后端全栈项目 By [程序员鱼皮](https://docs.qq.com/doc/DUFFRVWladXVjeUxW)\n\u003e\n\u003e **制作不易，请勿商用和二次售卖！！！**\n\n\n\n在线体验：[http://sqlfather.yupi.icu](http://sqlfather.yupi.icu)\n\n视频演示（使用教程）：[https://www.bilibili.com/video/BV1eP411N7B7/](https://www.bilibili.com/video/BV1eP411N7B7/)\n\n\n\n\u003e 如果您觉得本项目有帮助，给 UP 主一个关注和三连就是最大的支持，谢谢！\n\n\n\n前端代码仓库：[https://github.com/liyupi/sql-father-frontend-public](https://github.com/liyupi/sql-father-frontend-public)\n\n后端代码仓库：[https://github.com/liyupi/sql-father-backend-public](https://github.com/liyupi/sql-father-backend-public)\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666090763987-f768817c-89d6-4326-b7e1-5ad06d5cc875-20221019132239543-20221019132502106-20221019132511275.png)\n\n⭐️ 我在自己的 [编程知识星球](https://yupi.icu) 内给大家详细解读了这个项目的创作思路 + 技术选型 + 系统设计 + 源码解读 + 简历写法分享，如果你希望把这个项目写到简历上、或者深入学习，欢迎 [加入我的星球](https://yupi.icu) 观看。\n\n\n## 项目背景\n\n项目的创作起因就是鱼皮为了解决自己开发项目时反复写 SQL 建表和造数据的麻烦，顺便开源给大家一起来学习和完善~\n\n试想一下：如果我做新项目的时候，不用写建表 SQL、不用造数据，能直接得到一个造好了假数据的表，那该有多好！\n\n\u003e 有同学问为什么项目不叫 SQL Mother？那我问问你为什么继承叫父类？\n\n\n\n## 应用场景\n\n无论你是前端、后端、测试、数据开发、数据科学，还是研究方向的同学，相信这个工具都会对你有帮助！\n\n主要应用场景如下：\n\n1）通过填写可视化表单的方式，快速生成建表语句、模拟数据和代码，告别重复工作！\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666098192337-c6ef4c6f-1d41-421e-882f-a40b17f8790f-20221019132251475-20221019132502279-20221019132511408.png)\n\n2）支持多种快捷导入方式。比如已经有现成的数据表，可以直接导入建表语句，一键生成模拟数据；还可以直接导入 Excel 表格，快速完成建表；甚至还支持智能导入，输入几个单词就自动生成表格和数据！\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666098420835-59bfcd91-072c-45e9-a415-2fca70afd996-20221019132502336-20221019132511479.png)\n\n3）支持多种生成模拟数据的规则。比如固定值、随机值、正则表达式、递增值，甚至还支持选择词库来生成特定范围内的随机值！\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666099678320-ffafe59e-60c5-49c7-aeb4-1c20ba3c4f4a-20221019132502444-20221019132511599.png)\n\n4）支持词库、表设计、字段信息共享。可以学习或参考其他同学的库表设计，或者直接使用现成的库表和字段，一键生成或进行二次开发，协作万岁！\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666098509897-6fb00eee-79dd-4608-a364-8a0b5271a392-20221019132502525-20221019132511687.png)\n\n5）可以直接使用现成的词库来建立字典表，或者作为研究用的数据集，并支持二次完善词库！\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666099806973-f48785e1-3d6c-49c9-a093-77c234d4f8b1-20221019132502586-20221019132511780.png)\n\n\n\n## 值得学习\n\n项目本身功能完整（分为用户前台和管理后台）、达到上线标准、架构设计清晰、目录结构规范。\n\n前端用到了复杂的嵌套 \u0026 动态 \u0026 可折叠表单、代码编辑器；后端用到了多种主流设计模式、AOP 切面鉴权等，还是非常值得朋友们学习的。\n\n\u003e 也请大佬们请多多指教 🙏🏻\n\n\n\n## 功能大全\n\n### 用户前台\n\n- 可视化建表\n- 快捷导入建表\n  - 智能导入\n  - 导入表\n  - 导入配置\n  - 导入建表 SQL\n  - 导入 Excel\n- 一键生成\n  - SQL 建表、插入数据语句\n  - 模拟数据\n  - JSON 数据\n  - Java 代码\n  - 前端代码\n- 多种模拟数据生成规则\n  - 固定值\n  - 随机值\n  - 正则表达式\n  - 递增\n  - 定制词库\n- 词库共享\n  - 创建词库\n  - 词库继承\n  - 一键创建字典表\n  - 根据词库生成模拟数据（可以用来决定午饭吃什么哈哈）\n- 表信息共享\n  - 创建表信息\n  - 一键复制建表语句\n  - 一键导入表\n- 字段共享\n  - 创建字段\n  - 一键复制创建字段语句\n  - 一键导入字段\n- 举报\n\n\n\n### 管理后台\n\n- 用户管理\n- 词库管理\n- 表信息管理\n- 字段信息管理\n- 举报管理\n\n\n\n## 技术栈\n\n### 前端\n\n主要技术：\n\n- React 18\n- Umi 4.x\n- Ant Design 4.x 组件库\n- Ant Design Pro Components 高级组件\n- TypeScript 类型控制\n- Eslint 代码规范控制\n- Prettier 美化代码\n\n依赖库：\n\n- monaco-editor 代码编辑器\n- copy-to-clipboard 剪切板复制\n\n\n\n### 后端\n\n主要技术：\n\n- Spring Boot 2.7.x\n- MyBatis Plus 3.5.x\n- MySQL 8.x\n- Spring AOP\n\n依赖库：\n\n- FreeMarker：模板引擎\n- Druid：SQL 解析\n- datafaker：模拟数据\n- Apache Commons Lang3：工具库\n- Hutool：工具库\n- Gson：Json 解析\n- Easy Excel：Excel 导入导出\n- Knife4j：接口文档生成\n\n\n\n## 快速启动\n\n### 后端\n\n1. 运行 sql 目录下的 create_table.sql 建表\n2. 修改 application.yml 中的数据库地址为自己的\n3. 安装完 Maven 依赖后，直接运行即可\n4. 已经编写好了 Dockerfile，支持 Docker 镜像部署。\n\n\n\n### 前端\n\n安装依赖：\n\n```bash\nnpm run install\n```\n\n运行：\n\n```bash\nnpm run dev\n```\n\n打包：\n\n```bash\nnpm run build\n```\n\n\n\n## 系统设计\n\n主要分享系统的整体架构和核心设计，而传统 web 开发部分不做过多介绍。\n\n### 整体架构设计\n\n核心设计理念：将各输入方式统一为明确的 Schema，并根据 Schema 生成各类内容。\n\n架构设计图如下，即任意输入 =\u003e 统一 Schema =\u003e 任意输出：\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666144811181-37d5bd7f-28fa-4b17-9147-ae7de8de1585-20221019132502647-20221019132511901.png)\n\n系统分为以下几个核心模块，各模块职责分明：\n\n1. Schema 构造器：将各种不同的输入源转为统一的 Table Schema 定义\n2. 统一 Schema 定义：本质是一个 Java 类（JSON 配置），用于保存表和字段的信息\n3. 生成器：负责根据 Schema 生成数据和代码\n4. 共享服务：包括词库、表信息、字段信息共享\n\n\u003e 核心模块的代码都在后端 core 目录下\n\n\n\n### Schema 构造器\n\n核心类：TableSchemaBuilder，作用是将不同的参数统一收敛为 TableSchema 对象。\n\n包含如下方法：\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666144943025-0d62bf99-5ee6-4135-89da-a0bf270f3f49-20221019132502695-20221019132512014.png)\n\n其中，buildFromSql（根据 SQL 生成 Schema）使用了 Druid 数据库连接池自带的语法解析器，非常强大。（解析器这种东西一般不要自己写，有这时间你都能做几个项目了，写出来还没人家的好用)\n\n\n\n### Schema 定义\n\n用于保存表和字段的信息，结构如下：\n\n```json\n{\n  \"dbName\": \"库名\",\n  \"tableName\": \"test_table\",\n  \"tableComment\": \"表注释\",\n  \"mockNum\": 20,\n  \"fieldList\": [{\n    \"fieldName\": \"username\",\n    \"comment\": \"用户名\",\n    \"fieldType\": \"varchar(256)\",\n    \"mockType\": \"随机\",\n    \"mockParams\": \"人名\",\n    \"notNull\": true,\n    \"primaryKey\": false,\n    \"autoIncrement\": false\n  }]\n}\n```\n\n\n\n### 生成器\n\n#### 多种生成类型\n\n将每种生成类型定义为一个 Builder（core/builder 目录）：\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666145274014-bb582f01-31dd-442c-835a-64c1e9fd61a5-20221019132502741-20221019132512095.png)\n\n其中，对于 SQL 代码生成器（ SqlBuilder），使用方言来支持不同的数据库类型（策略模式），并使用单例模式 + 工厂模式创建方言实例。\n\n对于 Java、前端代码生成器（JavaCodeBuilder、FrontendCodeBuilder），使用 FreeMarker 模板引擎来生成。\n模板代码如下：\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666146737562-53f46d04-489d-4d00-ab9b-11cf237cd4a9-20221019132502769-20221019132512184.png)\n\n\n\n#### 多种模拟数据生成规则\n\n每种生成规则定义为一个 Generator，使用 DataGeneratorFactory（工厂模式）对多个 Generator 实例进行统一的创建和管理。\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666145631468-8d0d5dad-0cd8-41a5-8a8b-e65c5feb7829-20221019132502828-20221019132512285.png)\n\n使用 dataFaker 库实现随机数据生成（RandomDataGenerator）。\n\n使用 Generex 库实现正则表达式数据生成（RuleDataGenerator)。\n\n\n\n#### 统一的生成入口\n\n使用门面模式聚合各种生成类型，提供统一的生成调用和校验方法：\n\n![](https://xingqiu-tuchuang-1256524210.cos.ap-shanghai.myqcloud.com/1/1666145871478-af8512a5-d9c3-4166-8253-0304639c62b0-20221019132502858-20221019132512359.png)\n\n\n\n### 共享服务\n\n包括词库、表信息、字段信息共享，其实就是对这些实体的增删改查 web 服务，不多说了。\n\n\n\n## 更多讲解\n\n如果你希望获取该项目的完整详细讲解，欢迎加入 [鱼皮的编程知识星球](https://yupi.icu/) 。这是鱼皮的编程学习圈子，我在圈子内带大家从 0 到 1 分析解读这个项目、1 对 1 回答大家的问题。不仅让你也能独立做一个、还会教你怎么把这个项目写到简历上，项目经历 + 1。\n\n\n\n## 贡献指南\n\n欢迎各位朋友参与贡献，还请先仔细阅读以下内容：\n\n1. 在贡献前，请确保你对项目的代码和架构设计有一定的了解，而不是凭直觉去修改代码\n2. 可以从修复 issues 区 bug、处理反馈意见（[https://support.qq.com/product/440825](https://support.qq.com/product/440825)）、扩展项目功能等角度参与贡献\n3. 在提交代码前，请务必遵循项目的代码格式、命名等规范，并且做到最小改动（不需要改的内容，一个字符都不要动）\n\n\n\n## 致谢\n\n部分词库来源：[https://github.com/fighting41love/funNLP](https://github.com/fighting41love/funNLP)\n\n示例表信息来源：[https://open.yesapi.cn/list1.html](https://open.yesapi.cn/list1.html)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyupi%2Fsql-father-backend-public","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliyupi%2Fsql-father-backend-public","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyupi%2Fsql-father-backend-public/lists"}