You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
1 week ago | |
|---|---|---|
| apps/web-antd/src | 6 months ago | |
| templates | 1 week ago | |
| vue-vben-admin | 1 week ago | |
| .gitignore | 1 week ago | |
| README.md | 1 week ago | |
| ak_share.py | 4 months ago | |
| api_generator_vue.py | 6 months ago | |
| config.py | 6 months ago | |
| config.yml | 6 months ago | |
| cvideo2.py | 1 week ago | |
| data_engine.py | 4 months ago | |
| db.py | 6 months ago | |
| main.py | 6 months ago | |
| python_scaffolding.py | 1 week ago | |
| requirements.txt | 8 months ago | |
| stock_data.db | 4 months ago | |
| utils.py | 6 months ago | |
| vue.py | 6 months ago | |
README.md
SnailCodeGen
项目描述:
- JAVA、Python和VUE脚手架生成器,可以生成可执行的完整项目。
- 用于初始创建空项目也可以根据数据库的表生成可执行的完整项目 。
- VUE脚手架以vue-vben-admin框架为基础的脚手架,根据数据库的表和JAVA脚手架生成列表界面。能自动适配枚举,适配图片并增加上传组件。
- Python脚手架基于FastAPI + SQLAlchemy + Pydantic,复用JAVA脚手架的config.yml配置文件。
操作方式:
注 运行环境 Python 3.13.5 ;浏览器 Chrome 80+ ; npm 11.6.1+; node v22.20.0+ ; java 8/java 21; maven 3.8.0
# -------------------打包-------------------
Windows 运行命令:
python.exe -m pip install pyinstaller
python.exe -m PyInstaller --onefile --name generator generator.py
Mac/Linux 运行命令:
python3 -m pip install pyinstaller
python3 -m PyInstaller --onefile --name generator generator.py
python -m PyInstaller --onefile --name generator generator.py
C:\Users\DELL\AppData\Local\Programs\Python\Python313\python.exe -m PyInstaller --onefile --name generator generator.py
#------------JAVA脚手架执行操作----------------
generator.exe -h
options:
-h, --help #show this help message and exit
--tab #表名,多个用逗号分隔,例如: tab,tab2
--model #可选模块 xxlJob,minio,saToken,swagger,vue
--rew #是否覆盖已存在文件(默认不覆盖),不覆盖:false,覆盖:true
--conf #* 配置文件路径,默认路径./config.yml
--jdk #Java版本号,默认Java 8, JAVA21直接输入21
generator.exe --conf ./config.yml #空项目
generator.exe --model swagger #组件模块
generator.exe --tab HealthFun #生成表对应的接口
generator.exe --conf ./config.yml --tab HealthFun #组合命令
generator.exe --conf ./config.yml --model swagger #组合命令
generator.exe --conf ./config.yml --tab HealthFun --model swagger --jdk 21 --rew true #组合命令
generator.exe --model vue --tab table_names #vue 组件以及适配对应的枚举表
C:\Users\DELL\AppData\Local\Programs\Python\Python313\python.exe .\generator.py --model swagger # 不打包也可以直接运行
#----------vue脚手架---------------------------
C:\Users\DELL\AppData\Local\Programs\Python\Python313\python.exe .\frontend_vue.py health_fun
#------------Python脚手架执行操作----------------
python_scaffolding.py -h
options:
-h, --help #show this help message and exit
-c, --config #配置文件路径(默认: config.yml),复用JAVA脚手架配置
-o, --output #输出目录(默认: ./output)
-t, --tables #指定要生成的表名(默认: 全部)
--no-db #不连接数据库,使用示例数据
python python_scaffolding.py -c config.yml #连接数据库,生成全部表
python python_scaffolding.py -c config.yml -t user #生成指定表
python python_scaffolding.py -c config.yml --no-db #不连接数据库,使用示例数据
python python_scaffolding.py -c config.yml -o ./my_dir #指定输出目录
#------------生成的Python项目运行----------------
cd ./output/{mainModule}/{moduleName}
pip install -r requirements.txt
python main.py #启动FastAPI服务,默认 http://127.0.0.1:8000
# Swagger文档: http://127.0.0.1:8000/docs
目前已集成的组件:
基础组件 : java8(jdk corretto-1.8/21) + maven(3.8.0) + springboot + mybatis + mybatisplus 可选组件 : xxlJob + swagger + redis + mysql + minio + satoken 前端组件 : vue-vben-admin 框架 Python组件 : FastAPI + SQLAlchemy + Pydantic + Uvicorn
生成项目目录结构:
#java 脚手架目录
src
├── main
│ ├── java
│ │ └── com
│ │ └── test
│ │ └── api
│ │ ├── models
│ │ │ ├── common
│ │ │ └── config
│ │ │ ├── MybatisPlusConfig.java
│ │ │ ├── WebLogAspect.java
│ │ │ └── unit
│ │ │ ├── FilesUtil.java
│ │ │ ├── Md5HashUtil.java
│ │ │ └── vo
│ │ │ └── Result.java
│ │ ├── controller
│ │ │ └── HealthFunController.java
│ │ ├── entity
│ │ │ ├── BaseEntity.java
│ │ │ └── HealthFun.java
│ │ ├── mapper
│ │ │ └── HealthFunMapper.java
│ │ ├── service
│ │ │ ├── impl
│ │ │ │ └── HealthFunMPJBaseServiceImpl.java
│ │ │ └── HealthFunService.java
│ │ └── Application.java
│ └── resources
│ ├── mappers
│ │ └── HealthFunMapper.xml
│ ├── application.yml
│ ├── application-dev.yml
│ └── logback.xml
├── test
│ └── java
│ └── com
│ └── test
│ └── api
│ └── ApplicationTests.java
└── pom.xml
#Python 脚手架目录 (FastAPI + SQLAlchemy + Pydantic)
{mainModule}/{moduleName}/
├── main.py # FastAPI应用入口
├── requirements.txt # 依赖包
├── app/
│ ├── __init__.py
│ ├── config.py # 应用配置
│ ├── database.py # 数据库配置
│ ├── models/ # SQLAlchemy数据模型层
│ │ ├── __init__.py
│ │ └── {table_name}.py # 每张表对应一个Model
│ ├── schemas/ # Pydantic数据验证层
│ │ ├── __init__.py
│ │ └── {table_name}.py # 每张表对应Schema
│ ├── services/ # 业务逻辑层
│ │ ├── __init__.py
│ │ └── {table_name}_service.py
│ ├── routers/ # API路由层(控制器)
│ │ ├── __init__.py
│ │ └── {table_name}.py # 每张表对应Router
│ └── utils/
│ └── __init__.py
└── tests/
└── __init__.py
vue-vben-admin/
├── apps/ # 应用目录(不同 UI 框架的成品)
│ ├── web-antd/ # Ant Design Vue 版本
| | └──src
| | ├──api
| | | ├──core
| | | ├──user.ts #自动生成的接口调用
| | | └──...
| | ├──routes
| | | └──routes
| | | └──modules
| | | ├──user.ts #自动生成路由
| | | └──...
| | ├──views
| | | └──user
| | | ├──data.ts #自动生成数据适配
| | | ├──form.ts #自动生成表单适配
| | | └──form.ts #自动生成界面
│ ├── web-ele/ # Element Plus 版本
│ ├── web-naive/ # Naive UI 版本
│ ├── web-tdesign/ # TDesign 版本
│ └── backend-mock/ # Nitro Mock 服务
│
├── packages/ # 共享功能包(核心代码)
│ ├── @core/ # 框架无关的核心基础
│ │ ├── base/ # 基础工具、图标、类型定义
│ │ ├── ui-kit/ # UI 组件(表单、弹窗、菜单等)
│ │ └── composables/ # 共享组合式 API
│ ├── effects/ # 高级业务功能
│ │ ├── layouts/ # 布局组件
│ │ ├── common-ui/ # 通用 UI(加载、提示框等)
│ │ ├── access/ # 权限控制
│ │ └── hooks/ # 应用级 Hooks
│ └── stores/ # Pinia 状态管理
│
├── internal/ # 内部工具配置
│ ├── vite-config/ # Vite 配置预设
│ ├── tailwind-config/ # Tailwind CSS 配置
│ └── lint-configs/ # ESLint / Stylelint 规则
│
├── playground/ # 开发测试环境
├── docs/ # 项目文档
└── scripts/ # 脚本工具
Python API 接口调用方式
生成的Python项目使用FastAPI框架,所有接口统一使用 api_version Header替代 version(避免与业务字段冲突)。
# 启动服务后访问 Swagger 文档
http://127.0.0.1:8000/docs
# 分页查询 - POST /api/{table_name}/page
curl -X POST "http://127.0.0.1:8000/api/health_fun/page?page=1&page_size=10" \
-H "token: your_token" \
-H "api_version: 1.0"
# 详情查询 - POST /api/{table_name}/info?id=1
curl -X POST "http://127.0.0.1:8000/api/health_fun/info?id=1" \
-H "token: your_token" \
-H "api_version: 1.0"
# 新增 - POST /api/{table_name}/add
curl -X POST "http://127.0.0.1:8000/api/health_fun/add" \
-H "token: your_token" \
-H "Content-Type: application/json" \
-d '{"name": "test"}'
# 修改 - POST /api/{table_name}/modify
curl -X POST "http://127.0.0.1:8000/api/health_fun/modify" \
-H "token: your_token" \
-H "Content-Type: application/json" \
-d '{"id": 1, "name": "updated"}'
# 删除单个 - GET /api/{table_name}/remove/{id}
curl "http://127.0.0.1:8000/api/health_fun/remove/1" \
-H "token: your_token"
# 批量删除 - POST /api/{table_name}/removes
curl -X POST "http://127.0.0.1:8000/api/health_fun/removes" \
-H "token: your_token" \
-H "Content-Type: application/json" \
-d "[1, 2, 3]"
Python API 返回 JSON 格式
{
"code": 200,
"message": "success",
"data": {
"id": 1,
"name": "test",
"created_at": "2024-01-01T00:00:00",
"updated_at": "2024-01-01T00:00:00"
}
}
// 分页返回格式
{
"code": 200,
"message": "success",
"data": [],
"total": 100,
"page": 1,
"page_size": 10
}
脚手架目录结构:
codegen/
├── generator.py # java主程序
├── frontend_vue.py # vue主程序
├── python_scaffolding.py # python主程序
├── config.yml # 项目配置文件(JAVA/Python共用)
├── templates/ # 模板文件
│ ├── java/
│ │ ├── entity.java.j2
│ │ ├── controller.java.j2
│ │ └── ...
│ ├── vue/
│ │ ├── api.ts.j2
│ │ ├── data.ts.j2
│ │ └── ...
│ └── py/
│ ├── main.py.j2
│ ├── model.py.j2
│ ├── schema.py.j2
│ ├── service.py.j2
│ ├── router.py.j2
│ ├── config.py.j2
│ ├── database.py.j2
│ └── requirements.txt.j2
├── utils.py # 公共方法
├── db.py # 数据库操作
└── requirements.txt # 依赖包
api 返回 json 格式
{
"success": true,
"message": "",
"code": 200,
"result": {
},
"timestamp": 1783590380098
}