Files
easygoadmin-wiki/EasyGoAdmin_Gin_EleVue/zh/generator/demo.md
T
2026-10-25 17:24:27 +08:00

63 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 10.7 实战案例
:::tip 概述
以 `gin_example` 为对象完整走一遍生成流程:预览 → 生成 → 重启 → 验证。生成产物应与项目内置 example 模块高度一致——这也是检验模板正确性的手段。
:::
## 准备
- 数据库已导入种子脚本(gin_example 存在)
- 后端依赖就绪(可 `go run`)
## 步骤一:预览
```bash
make gen-preview TABLES="gin_example|示例表"
```
观察 stdout 输出的文件清单与内容:dto 标签、ModuleSpec 声明、RouteSpec 块、前端页面。对照 [3.11 完整代码清单](/zh/guide/code-list.html)。
## 步骤二:生成
```bash
make gen TABLES="gin_example|示例表"
```
结果分类:
| 分类 | 本例预期 |
|---|---|
| generated/overwritten | 视 overwrite 策略(example 已存在 → false 时全 skipped,true 时覆盖) |
| menu | 幂等(已存在同名菜单则不重复建) |
| dict | example_status 已存在 → 跳过或补项 |
| route | router.go 已有 CExample 块 → 幂等跳过 |
## 步骤三:重启验证
```bash
make run # 重启使路由注册生效
pnpm dev # 前端(如页面有调整)
```
验证点:
- [ ] 接口可访问(Swagger 看 /api/example/*)
- [ ] 菜单出现且权限节点齐全
- [ ] 页面增删改查、导入导出正常
- [ ] 字典回填 statusText 正常
## 从 example 到你的模块
```text
① 建表(COMMENT 写全枚举取值;唯一列建 uk_ 索引;租户级加 tenant_id)
② make gen TABLES="gin_order|订单"
③ 重启 → 页面验证
④ 按业务手写补充(导入导出、特殊校验、数据权限声明)
```
生成解决 80% 的标准形态,20% 的业务差异走手写方法与声明微调——这正是 ModuleSpec"声明 + 逃生舱"设计的呼应。
## 相关
- [10.8 常见问题](/zh/generator/faq.html)