# AutoCodeGen **Repository Path**: frsf/AutoCodeGen ## Basic Information - **Project Name**: AutoCodeGen - **Description**: 基于 FreeMarker 代码生成器 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-07-24 - **Last Updated**: 2024-10-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AutoCodeGen
#### 生成代码
指定代码生成模板,这里配置了SOA模板,导出数据为ZIP压缩包
#### 代码预览
默认的SOA模板如下
## 自定义模板
1. 在resources/templates/`模板名称`
2. 在枚举类中添加你想要的模板名称,需要与`模板名称`的模板文件夹名称对应,`top.frsf.autocodegen.meta.TemplateNameEnum`
```text
# first param:前端下拉框的名称
# second param:模板文件夹名称
SOA("SOA", "soa"),
MP("Mybatis-Plus", "mp"),
Ruoyi("RuoYi", "ruoyi");
```
3. 按照文件夹结构你想要的文件目录及内容,代码会广搜你的模板及其文件路径,让生成的代码结构与你定义的保持一致
```text
# eg:soa
soa
├─service
│ ├─model-api
│ │ DTO.java.ftl
│ │ IService.java.ftl
│ │ ReqDTO.java.ftl
│ │
│ ├─model-service
│ │ Convert.java.ftl
│ │ Mapper.java.ftl
│ │ ServiceImpl.java.ftl
│ │
│ └─model-util
│ PO.java.ftl
│
└─web
└─model-web
Controller.java.ftl
Convert.java.ftl
VO.java.ftl
```
4. freemarker内置模型数据
`top.frsf.autocodegen.controller.CodeGenController.getDataModel`
```text
AutoTable autoTable = autoTableService.getById(tableId);
outer.put("TableName", autoTable.getTableName());
outer.put("ClassName", autoTable.getClassName());
outer.put("TableComment", autoTable.getTableComment());
outer.put("Author", autoTable.getAuthor());
outer.put("Email", autoTable.getEmail());
outer.put("DateTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// FiledModel
List