中台框架模塊開發實踐-用 Admin.Core 代碼生成器生成通用代碼生成器的模塊代碼

来源:https://www.cnblogs.com/morang/p/18277156/zhontai_admin_core_module_dev_use_toproject
-Advertisement-
Play Games

之前分享中台 Admin.Core 的模塊代碼生成器,陸續也結合群友們的反饋,完善了一些功能和模板上的優化,而本篇將基於此代碼生成器生成一個通用代碼生成器模塊的基本代碼 後續再在此代碼的基礎上進行完善,製作一個通用的代碼生成器 ...


前言

之前分享中台 Admin.Core 的模塊代碼生成器,陸續也結合群友們的反饋,完善了一些功能和模板上的優化,而本篇將基於此代碼生成器生成一個通用代碼生成器模塊的基本代碼

後續再在此代碼的基礎上進行完善,製作一個通用的代碼生成器

要做一個項目,首先我們要弄清楚需求,這裡簡單規划了下所需要的功能模塊

可從腦圖中看到,基本除了項目生成這塊需要添加代碼,相關模塊的增刪改查都可以由代碼生成器來生成

準備

本文開發完成的項目將放在:yimogit/Emo.Dev

本篇開發代碼在我 Fork 的倉庫 yimogit/Admin.Core

本文主要的閱讀者:開發完成後的代碼生成器的使用者,使用/將要用 Admin.Core 框架的猿們,如果覺得有用,歡迎點贊留言

實現

  • 效果一覽

超大gif

項目代碼準備

git clone https://github.com/yimogit/Admin.Core.git

在運行項目後連接到資料庫執行 sql 創建

--添加視圖
INSERT INTO ad_view (Id,ParentId,Name,Label,"Path",Description,Cache,Sort,Enabled,CreatedUserId,CreatedUserName,CreatedUserRealName,CreatedTime,ModifiedUserId,ModifiedUserName,ModifiedUserRealName,ModifiedTime,IsDeleted) VALUES
         (558530915442693,0,NULL,'代碼管理',NULL,NULL,0,99,1,161223411986501,'admin','管理員','2024-06-16 16:08:08',161223411986501,'admin','管理員','2024-06-16 16:08:16',0),
         (558531082424325,558530915442693,'codegen','代碼生成','dev/codegen/index',NULL,0,1,1,161223411986501,'admin','管理員','2024-06-16 16:08:49',NULL,NULL,NULL,NULL,0);
-- 添加許可權
INSERT INTO ad_permission (Id,ParentId,Label,Code,"Type",ViewId,Name,"Path",Redirect,Icon,Hidden,Opened,NewWindow,"External",IsKeepAlive,IsAffix,Link,IsIframe,Sort,Description,Enabled,CreatedUserId,CreatedUserName,CreatedUserRealName,CreatedTime,ModifiedUserId,ModifiedUserName,ModifiedUserRealName,ModifiedTime,IsDeleted) VALUES
         (558531409440773,0,'代碼生成',NULL,2,558531082424325,'devgen','/codegen',NULL,'ele-Memo',0,0,0,0,0,0,NULL,0,5,NULL,1,161223411986501,'admin','管理員','2024-06-16 16:10:09',161223411986501,'admin','管理員','2024-06-16 16:10:55',0);

或根據前文 中台框架模塊開發實踐-代碼生成器的添加及使用 在前臺添加代碼生成器菜單

生成器的生成方式說明

代碼生成器支持DBFirst和CodeFirst兩種方式

  1. DBFirst 需要選擇數據源並選擇數據表進行生成配置的保存

  1. CodeFirst 可以直接生成配置,配置保存後再使用生成遷移SQL或者將遷移執行到資料庫的方式同步資料庫表信息

這裡為了更方便的生成,做了一個 json 的導入導出,可以快速複製/導入分享的配置,下麵會貼出配置,直接導入即可,導入時會將id重置,都為新增

建立數據模型並生成代碼

通過前面理的需求,可以創建相關模型

  • 模板分組

    • 模板信息實體
    • DevGroup
  • 模板列表

    • 模板信息實體
    • DevTemplate
  • 項目生成

    • 以項目,項目模型,模型欄位組成
    • DevProject
    • DevProjectModel
    • DevProjectModelField

對應代碼生成器數據如下,提供這幾個模型的基礎增刪改查功能

對應 json 配置,導入即可

[{"id":563489262788677,"authorName":"yimo","tablePrefix":true,"generateType":"2","dbKey":"admindb","dbType":"Sqlite","tableName":"dev_template","namespace":"ZhonTai.Module.Dev","entityName":"DevTemplate","busName":"模板","apiAreaName":"dev","baseEntity":"EntityBase","menuPid":"代碼管理","menuAfterText":"管理","backendOut":"E:\\CodeGenOutput\\ZhonTai.Module.Dev","frontendOut":"E:\\CodeGenOutput","dbMigrateSqlOut":"E:\\MigrateSqls","comment":"","usings":"ZhonTai.Module.Dev.Domain.DevGroup","genEntity":false,"genRepository":false,"genService":false,"genAdd":true,"genUpdate":true,"genDelete":true,"genGetList":true,"genSoftDelete":true,"genBatchDelete":true,"genBatchSoftDelete":true,"fields":[{"id":563489262813253,"codeGenId":563489262788677,"dbKey":"","columnName":"Name","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"模板名稱","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":1,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563489262813254,"codeGenId":563489262788677,"dbKey":"","columnName":"GroupId","columnRawName":null,"netType":"long","dbType":"","comment":"","defaultValue":"","title":"模板分組","isPrimary":false,"isNullable":false,"length":"64","editor":"my-bussiness-select","position":2,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"DevGroupEntity","includeMode":0,"includeEntityKey":"Name","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563489262813255,"codeGenId":563489262788677,"dbKey":"","columnName":"Path","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"生成路徑","isPrimary":false,"isNullable":true,"length":"500","editor":"el-input","position":3,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563489262813256,"codeGenId":563489262788677,"dbKey":"","columnName":"Content","columnRawName":null,"netType":"string","dbType":"text","comment":"","defaultValue":"","title":"模板內容","isPrimary":false,"isNullable":false,"length":"-1","editor":"my-input-textarea","position":5,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"}]},{"id":563487794356293,"authorName":"yimo","tablePrefix":true,"generateType":"1","dbKey":"admindb","dbType":"Sqlite","tableName":"dev_group","namespace":"ZhonTai.Module.Dev","entityName":"DevGroup","busName":"模板組","apiAreaName":"dev","baseEntity":"EntityBase","menuPid":"代碼管理","menuAfterText":"管理","backendOut":"E:\\CodeGenOutput\\ZhonTai.Module.Dev","frontendOut":"E:\\CodeGenOutput","dbMigrateSqlOut":"E:\\MigrateSqls","comment":"","usings":null,"genEntity":true,"genRepository":true,"genService":true,"genAdd":true,"genUpdate":true,"genDelete":true,"genGetList":true,"genSoftDelete":true,"genBatchDelete":true,"genBatchSoftDelete":true,"fields":[{"id":563487794380869,"codeGenId":563487794356293,"dbKey":"","columnName":"Name","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"模板組名稱","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563487794380870,"codeGenId":563487794356293,"dbKey":"","columnName":"Remark","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"備註","isPrimary":false,"isNullable":true,"length":"500","editor":"my-input-textarea","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"}]},{"id":563486126821445,"authorName":"yimo","tablePrefix":true,"generateType":"2","dbKey":"admindb","dbType":"Sqlite","tableName":"dev_project_model_field","namespace":"ZhonTai.Module.Dev","entityName":"DevProjectModelField","busName":"項目模型欄位","apiAreaName":"dev","baseEntity":"EntityBase","menuPid":null,"menuAfterText":"管理","backendOut":"E:\\CodeGenOutput\\ZhonTai.Module.Dev","frontendOut":"E:\\CodeGenOutput","dbMigrateSqlOut":"E:\\MigrateSqls","comment":"","usings":"ZhonTai.Module.Dev.Domain.DevProjectModel","genEntity":false,"genRepository":false,"genService":false,"genAdd":true,"genUpdate":true,"genDelete":true,"genGetList":true,"genSoftDelete":true,"genBatchDelete":true,"genBatchSoftDelete":true,"fields":[{"id":563486126850117,"codeGenId":563486126821445,"dbKey":"","columnName":"Name","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"欄位名稱","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563486126850118,"codeGenId":563486126821445,"dbKey":"","columnName":"Description","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"欄位描述","isPrimary":false,"isNullable":true,"length":"-1","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563486126850119,"codeGenId":563486126821445,"dbKey":"","columnName":"DataType","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"欄位類型","isPrimary":false,"isNullable":true,"length":"64","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563486126850120,"codeGenId":563486126821445,"dbKey":"","columnName":"IsRequired","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"是否必填","isPrimary":false,"isNullable":true,"length":"64","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563486126850121,"codeGenId":563486126821445,"dbKey":"","columnName":"MaxLength","columnRawName":null,"netType":"int","dbType":"","comment":"","defaultValue":"","title":"最大長度","isPrimary":false,"isNullable":true,"length":"-1","editor":"el-input-number","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563486126850122,"codeGenId":563486126821445,"dbKey":"","columnName":"MinLength","columnRawName":null,"netType":"int","dbType":"","comment":"","defaultValue":"","title":"最小長度","isPrimary":false,"isNullable":true,"length":"-1","editor":"el-input-number","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563492098199621,"codeGenId":563486126821445,"dbKey":"","columnName":"ModelId","columnRawName":null,"netType":"long","dbType":"","comment":"","defaultValue":"","title":"模型Id","isPrimary":false,"isNullable":false,"length":"64","editor":"my-bussiness-select","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"DevProjectModel","includeMode":0,"includeEntityKey":"Name","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"}]},{"id":563484091809861,"authorName":"yimo","tablePrefix":true,"generateType":"2","dbKey":"admindb","dbType":"Sqlite","tableName":"dev_project_model","namespace":"ZhonTai.Module.Dev","entityName":"DevProjectModel","busName":"項目模型","apiAreaName":"dev","baseEntity":"EntityBase","menuPid":"代碼管理","menuAfterText":"管理","backendOut":"E:\\CodeGenOutput\\ZhonTai.Module.Dev","frontendOut":"E:\\CodeGenOutput","dbMigrateSqlOut":"E:\\MigrateSqls","comment":"","usings":"ZhonTai.Module.Dev.Domain.DevProject","genEntity":false,"genRepository":false,"genService":false,"genAdd":true,"genUpdate":true,"genDelete":true,"genGetList":true,"genSoftDelete":true,"genBatchDelete":true,"genBatchSoftDelete":true,"fields":[{"id":563484091834437,"codeGenId":563484091809861,"dbKey":"","columnName":"Name","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"模型名稱","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563484091834438,"codeGenId":563484091809861,"dbKey":"","columnName":"Code","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"模型編碼","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563484091834439,"codeGenId":563484091809861,"dbKey":"","columnName":"Remark","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"備註","isPrimary":false,"isNullable":true,"length":"-1","editor":"my-input-textarea","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563484091834440,"codeGenId":563484091809861,"dbKey":"","columnName":"ProjectId","columnRawName":null,"netType":"long","dbType":"","comment":"","defaultValue":"","title":"所屬項目","isPrimary":false,"isNullable":false,"length":"64","editor":"my-bussiness-select","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"DevProject","includeMode":0,"includeEntityKey":"Name","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"}]},{"id":563483673227333,"authorName":"yimo","tablePrefix":true,"generateType":"2","dbKey":"admindb","dbType":"Sqlite","tableName":"dev_project","namespace":"ZhonTai.Module.Dev","entityName":"DevProject","busName":"項目","apiAreaName":"dev","baseEntity":"EntityBase","menuPid":"代碼管理","menuAfterText":"管理","backendOut":"E:\\CodeGenOutput\\ZhonTai.Module.Dev","frontendOut":"E:\\CodeGenOutput","dbMigrateSqlOut":"E:\\MigrateSqls","comment":"","usings":"","genEntity":false,"genRepository":false,"genService":false,"genAdd":true,"genUpdate":true,"genDelete":true,"genGetList":true,"genSoftDelete":true,"genBatchDelete":true,"genBatchSoftDelete":true,"fields":[{"id":563483673256005,"codeGenId":563483673227333,"dbKey":"","columnName":"Name","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"項目名稱","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563483673284677,"codeGenId":563483673227333,"dbKey":"","columnName":"Code","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"項目編碼","isPrimary":false,"isNullable":false,"length":"200","editor":"el-input","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":true,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"0","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"},{"id":563483673284678,"codeGenId":563483673227333,"dbKey":"","columnName":"Remark","columnRawName":null,"netType":"string","dbType":"","comment":"","defaultValue":"","title":"備註","isPrimary":false,"isNullable":true,"length":"-1","editor":"my-input-textarea","position":0,"whetherCommon":false,"whetherRetract":false,"whetherQuery":false,"whetherAdd":true,"whetherUpdate":true,"whetherTable":true,"whetherList":true,"indexMode":null,"isUnique":false,"queryType":"6","dictTypeCode":"","includeEntity":"","includeMode":0,"includeEntityKey":"","displayColumn":"","valueColumn":"","pidColumn":"","effectType":"input","frontendRuleTrigger":"blur"}]}]

生成模型一覽

模板的模型配置參考

生成的後端代碼(E:\CodeGenOutput\ZhonTai.Module.Dev)

前端代碼( E:\CodeGenOutput\views)

在 Admin.Core 中使用生成的代碼

如果已經有項目可以直接添加對庫的引用,這裡直接新建一個項目 Emo.Dev

dotnet new install ZhonTai.Template::8.2.0
dotnet new MyApp -n Emo.Dev

可以看到這裡只生成了後端介面,目前 v8.2.0 還不支持前端代碼的生成,所以我們還需要手動去將對應版本的 前端代碼 下載一份到項目中(只保留),並調整下目錄結構,前端代碼放到 admin-ui ,後端代碼放到 admin-api

運行前後端項目,確認項目運行沒問題後開始添加通用代碼生成器模塊代碼。後續任意模塊代碼都可以參考步驟

1.後端項目引用關係配置

  • 將生成的模塊代碼 ZhonTai.Module.Dev 拷貝到在新項目中

修改庫中的引用,預設生成的 ZhonTai.Module.Dev.csproj 引用是相對源碼的路徑

  • 所以需要修改下,直接引用 ZhonTai.Admin 的包
  <ItemGroup>
    <PackageReference Include="ZhonTai.Admin" Version="$(PackageZhonTaiVersion)">
      <CopyToOutputDirectory>***.xml</CopyToOutputDirectory>
    </PackageReference>
  </ItemGroup>
  • Host 項目添加對 ZhonTai.Module.Dev 的引用

  • 簽名文件未找到報錯處理

添加完成後如果提示前面文件找不到,可將Api下的簽名文件複製過來或自行生成

我這裡是將Emo.Dev.Api的key.snk文件複製到了platform文件夾,並改了02.build/Directory.Build.props 中程式集簽名的文件路徑到 ..\kye.snk ,這樣就可以讓項目中的所有程式集就用這個前面文件

  • 整體修改情況

2.後端配置修改

  • 修改應用配置: ConfigCenter/appconfig.json

    • 修改程式集名稱和swagger配置
    • //程式集名稱
      "assemblyNames": [ "Emo.Dev.Api", "ZhonTai.Admin", "ZhonTai.Module.Dev" ],
      //Swagger介面文檔
      "swagger": [
          ...
          {
            "name": "代碼生成",
            "code": "dev",
            "version": "v8.2.0",
            "description": "代碼生成"
          }
          ...
      ]
      

  • 修改資料庫配置: ConfigCenter/dbconfig.json

    • 增加dbs配置節點:指定資料庫的key,assemblyNames,type,connectionString
    • 預設將創建實體表對應的數據表

生成的資料庫表

修改後配置後 Ctrl+F5運行即可查看代碼生成介面

3.前端項目配置

  • 先安裝包 pnpm install
  • 複製生成的代碼 views 到前端項目

  • 修改並執行 gen/gen-api.js 生成前端項目文件

增加正確的後端swagger地址,當前版本預設的gen-api.js有問題需要修改路由首碼,如圖所示,如果要將/app修改為其他的,幾個地方都要修改

執行:npm run gen:api 進行介面文件生成

  • 運行項目:npm run dev 開始配置菜單和視圖

4.系統中配置菜單

  1. 同步模塊介面

  1. 添加視圖地址
  • 父級視圖可以不添加命名,參考其他的添加即可
  • 視圖地址和views下文件路徑對應

  1. 添加分組及菜單
  • 【分組】為一級菜單,【菜單】為二級菜單,【許可權點】對應為按鈕
  • 預設選擇了視圖將會自動帶出視圖信息,直接保存介面

  1. 配置許可權點

這裡需要註意,選擇api介面時點擊圖標咱開下級,否則將會選中父級的編碼和名稱

當然,也可以自行改下代碼 讓api介面選中的時候判斷最下級才選中

配置完成如下所示

  1. 刷新頁面即可訪問到新添加的代碼管理模塊
  • 如果創建後訪問報錯,大概率是因為還沒有初始化資料庫
  • 訪問示例

5.複製生成器附帶的樣式

因為在做代碼生成器的時候為了生成更舒服一點,添加了一些通用的樣式,但是沒有提交到主庫,所以這裡可以將我的自定義樣式複製到自己的項目中

至此,成功將生成的代碼應用到獨立項目中

後語

花了一天的時間重新整理了代碼生成器的使用,將其應用到一個獨立項目中,在此期間也發現框架的一些問題,給作者提了PR,也在這個過程中學到許多

對於Admin.Core框架,總體來講使用起來還是很順暢的,代碼也比較好閱讀,簡單的 crud 結合代碼生成器,做一些小項目,完全是夠用的了

相關文檔

未經許可,禁止轉載!!!
作者:易墨
Github:yimogit
純靜態工具站點:metools


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 集合工廠 List<String> friends = Arrays.asList("Raphael", "Olivia"); friends.set(0, "Richard"); friends.add("Thibaut"); ← 拋出一個UnsupportedModificationExcept ...
  • 1、概述 Spring MVC是Spring Framework的Web開發部分,是基於Java實現MVC的輕量級Web框架。 官方文檔:https://docs.spring.io/spring-framework/docs/4.3.24.RELEASE/spring-framework-refe ...
  • 後兩次PTA總結 首先來看看第七次: 第七次相比於之前,添加了互斥開關元器件而且引入了並聯互串等等接法,按照我之前的設計,作出改動不算太難,我之前的遞歸已經可以按照順序儲存所以的元器件到一起去了,主要還是歸功於將串並聯電路繼承自元器件的方式十分有效,這樣就能夠將串並聯電路當作元器件一起處理,再按照遞 ...
  • 1. Spring MVC 獲取三個域(request請求域,session 會話域,application 應用域)對象的方式 @目錄1. Spring MVC 獲取三個域(request請求域,session 會話域,application 應用域)對象的方式2. Servlet中的三個域對象3 ...
  • ​《FFmpeg開發實戰:從零基礎到短視頻上線》一書的“10.2 FFmpeg推流和拉流”提到直播行業存在RTSP和RTMP兩種常見的流媒體協議。除此以外,還有比較兩種比較新的流媒體協議,分別是SRT和RIST。 其中SRT全稱為Secure Reliable Transport,中文叫做安全可靠傳 ...
  • 主題介紹 BeaconNav是基於typecho開發的一款導航主題,Beacon是燈塔的意思,希望使用者在知識的海洋里能夠如同有燈塔指引一樣目標明確,永遠不會迷失方向。 演示站點:https://nav.ilaozhu.com 主題特點 響應式設計,適配手機、平板、電腦等設備; 支持自定義 LOGO ...
  • 簡介: Redis是一款開源的使用ANSI C語言編寫、遵守BSD協議、支持網路、可基於記憶體也可持久化的日誌型、Key-Value高性能資料庫。Redis與其他Key-Value緩存產品相比有以下三個特點: 支持數據持久化,可以將記憶體中的數據保存在磁碟中,重啟可再次載入使用 支持簡單的Key-Val ...
  • 一:背景 1. 講故事 早就聽說過有什麼 網路邊緣計算,這次還真給遇到了,有點意思,問了下 chatgpt 這是幹嘛的 ? 網路邊緣計算是一種計算模型,它將計算能力和數據存儲位置從傳統的集中式數據中心向網路邊緣的用戶設備、感測器和其他物聯網設備移動。這種模型的目的是在接近數據生成源頭的地方提供更快速 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...