# Code Generator

## Page Guide

- **Scenario**: Generate backend CRUD, frontend pages, and basic APIs from database tables.
- **Prerequisite**: Database tables, comments, primary keys, dictionaries, permission identifiers, and menu paths have been designed.
- **Path**: System Tools -> Code Generation -> Import Table -> Configure Fields -> Preview -> Generate.
- **Acceptance Criteria**: Generated code compiles, APIs are accessible, and the frontend pages support list, add, edit, delete, and export.

## 1. Workflow

```mermaid
%%{init: {"flowchart": {"htmlLabels": false}}}%%
flowchart LR
  A["Design database table"] --> B["Import table"]
  B --> C["Configure generation info"]
  C --> D["Configure field controls"]
  D --> E["Preview code"]
  E --> F["Generate or download"]
  F --> G["Merge into source"]
  G --> H["Add menu permission"]
  H --> I["Integration test"]
```

## 2. Table Design Suggestions

| Item | Recommendation |
| --- | --- |
| Table name | Use a business prefix and avoid conflicts with system tables. |
| Primary key | Keep consistent with existing project style. |
| Column comments | Required for page labels and export headers. |
| Status fields | Reuse dictionaries when possible. |
| Create/update fields | Keep consistent with the project's common fields. |
| Tenant field | Add it early when data isolation is required. |
| Logical delete | Follow the project-wide strategy. |

## 3. Field Configuration

| Config | Description |
| --- | --- |
| Java type | Backend entity field type. |
| Query mode | Equals, like, range, and other query modes. |
| List display | Whether the column is displayed in the list. |
| Form display | Whether the column is displayed in add/edit forms. |
| Required | Whether frontend required validation is generated. |
| Control type | Input, select, date, radio, checkbox, and other controls. |
| Dictionary type | Dictionary used for status or enum labels. |

## 4. Post-generation Checks

1. Package and module names are correct.
2. Controller path follows API conventions.
3. Permission identifiers match menu buttons.
4. Mapper XML is scanned.
5. Frontend API path is correct.
6. Route and menu are configured.
7. Import/export display follows column comments.
8. List, add, edit, delete, and pagination pass smoke tests.

## 5. FAQ

### Generated code does not compile

Check the package name, module name, dependent modules, entity types, Mapper scan path, and Lombok annotations.

### Frontend page requests return 404

Check the backend Controller path, frontend API path, proxy prefix, and menu route.

### Buttons are not visible

Check menu button permissions, role authorization, and frontend permission identifiers.

### Dictionary labels are not displayed

Check whether the dictionary type exists, whether the dictionary values are enabled, and whether the field is configured with a dictionary type.

## 6. Secondary Development Entry Points

| Type | Path Or API | Description |
| --- | --- | --- |
| Frontend page | `vue3/src/views/tool/gen` | Code generation page. |
| Backend module | `springboot/fastbee-plugs/fastbee-generator` | Generator core. |
| Backend API | `/tool/gen` | Generator APIs. |
| Tables | `gen_table`, `gen_table_column` | Table and column generation configuration. |
| Dictionary API | `/system/dict/type`, `/system/dict/data` | Dictionary configuration. |

## 7. Related Docs

* [Vue3 Frontend Development](https://www.fastbee.cn/doc/en/business/v2/dev/vue3-development.html)
* [Backend Module Map](https://www.fastbee.cn/doc/en/business/v2/dev/backend-module-map.html)
* [Data Model Map](https://www.fastbee.cn/doc/en/business/v2/dev/data-model-map.html)
