Files
yidaima/RuoYi-Vue/docs/code-template-bundles.md

3.3 KiB
Raw Permalink Blame History

代码模板包接入说明

当前默认模板包是 qing。新增模板时,不再改生成服务里的固定 ID 分支,而是通过模板包元数据和模板记录接入。

新增模板包步骤

  1. sys_template_bundle 增加一条启用记录。
insert into sys_template_bundle
(bundle_code, bundle_name, description, status, is_default,
 support_backend, support_frontend, support_admin_frontend, support_sql,
 sort_order, create_by, create_time)
values
('vue3-plus', 'Vue3 Plus Template', 'Spring Boot + Vue3 runnable template', '0', '0',
 '1', '1', '1', '1', 20, 'admin', sysdate());
  1. sys_template 为每个支持的目标类型增加模板记录,并设置同一个 bundle_code
insert into sys_template
(template_name, template_path, template_desc, template_type, bundle_code, template_status, create_by, create_time, remark)
values
('Vue3 Plus Backend Template', '/vue3-plus/backend', 'Backend template', 'backend', 'vue3-plus', 0, 'admin', sysdate(), 'vue3-plus'),
('Vue3 Plus Admin Frontend Template', '/vue3-plus/admin_frontend', 'Admin frontend template', 'admin_frontend', 'vue3-plus', 0, 'admin', sysdate(), 'vue3-plus'),
('Vue3 Plus Portal Frontend Template', '/vue3-plus/frontend', 'Portal frontend template', 'frontend', 'vue3-plus', 0, 'admin', sysdate(), 'vue3-plus');
  1. 为这些模板补齐 sys_template_filesys_project_structure

  2. 前台生成页会从 /front/project/options/code-templates 读取启用模板包,创建或更新项目时提交 codeTemplate

  3. 预览页会从 /front/project/{projectId}/template-types 读取当前项目支持的目标类型,按返回值渲染结构 Tab。

字段约定

  • bundle_code: 模板包唯一编码,例如 qingvue3-plus
  • template_type: 目标类型,当前支持 backendfrontendadmin_frontendsql
  • front_project.code_template: 项目选择的模板包。为空时后端回退到默认模板包 qing

如果模板包暂不支持某一目标类型,把 sys_template_bundle.support_* 设为 0,前台预览和后端批量下载都会跳过该类型。

完整项目反向生成

模板反向生成使用 qing-compatible 投影,不再把上传项目的每个源码文件都写成动态模板文件:

  • 每次创建一个模板包,以及 backendadmin_frontendfrontend 三个类型模板。
  • 普通源码、配置和二进制资源按类型压缩为 skeleton 制品,写入 sys_template_artifact
  • 从后端选择分层文件最完整的一组业务代码作为代表样例,转换为 entity.java.vmmapper.java.vmservice.java.vmserviceImpl.java.vmcontroller.java.vmmapper.xml.vm
  • 两个 Vue 工程中与代表样例对应的页面/API转换为 Qing 的按表槽位,其余文件保留在 skeleton 中。
  • table_id = 0 的结构节点按项目中的每张表展开;项目级节点仍只生成一次。
  • 生成项目时先渲染动态槽位,再合并 skeleton动态输出与 skeleton 同名时以动态输出为准。
  • SQL继续使用现有 SQL 生成链路,因此不会额外创建 template_type = sql 的模板记录。

部署升级时需要先执行 sql/template_artifacts.sql。反向生成的模板包和类型模板默认保持停用完成试生成、Maven 编译、两个前端构建和 SQL 验证后再启用。