# 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

JDK-8 Springboot MySQL8.0

## 项目说明 - 基于 FreeMarker 代码生成器 - 感谢开源项目作者们代码所提供的帮助 - 参考开源项目:https://gitee.com/makunet/maku-generator.git - 前端地址:https://gitee.com/frsf/friot-admin/tree/AutoCodeGenFront/ - 前端分支:AutoCodeGenFront ## 使用说明 1. 导入SQL文件 2. 更改配置文件里面的数据源连接信息 3. 前端项目已经打包到resources/static文件夹下,无需配置 4. 运行项目控制台会有后台跳转连接以及Swagger地址 #### 运行控制台 ```text ======================================================================================================================== FRSF /\_/\ ( o o) View: http://localhost:5501 =\ > ^ < API: http://localhost:5501/doc.html \ / \ > / \ / / \ / / \ /___/ \___ (_____________________) ======================================================================================================================== ``` #### 导入数据表信息 首先需要添加数据源信息,再选择数据源下的数据表
#### 生成代码 指定代码生成模板,这里配置了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 fieldListByTableId = autoFieldService.list(Wrappers.lambdaQuery(AutoField.class) .eq(AutoField::getTableId, tableId)); ArrayList> filedList = new ArrayList<>(fieldListByTableId.size()); outer.put("FiledList", filedList); fieldListByTableId.forEach(field -> { HashMap inner = new HashMap<>(); inner.put("FieldName", field.getFieldName()); inner.put("FieldComment", field.getFieldComment()); inner.put("FieldType", field.getFieldType()); inner.put("CaseName", field.getCaseName()); inner.put("CaseType", field.getCaseType()); inner.put("OrderNum", field.getOrderNum()); inner.put("MainKey", field.getMainKey()); filedList.add(inner); }); filedList.sort(Comparator.comparingInt(o -> (Integer) o.get("OrderNum"))); ```