From 636de24762ac6d32b61c31ee6e328a5b3cbde3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=BB=BA=E7=A5=A5?= <958464639@qq.com> Date: Mon, 20 May 2024 17:27:02 +0800 Subject: [PATCH 1/3] 520 --- ...345\273\272\351\246\226\344\270\252Api.md" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "\345\215\242\345\273\272\347\245\245/20240520-\345\210\233\345\273\272\351\246\226\344\270\252Api.md" diff --git "a/\345\215\242\345\273\272\347\245\245/20240520-\345\210\233\345\273\272\351\246\226\344\270\252Api.md" "b/\345\215\242\345\273\272\347\245\245/20240520-\345\210\233\345\273\272\351\246\226\344\270\252Api.md" new file mode 100644 index 0000000..de896c2 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240520-\345\210\233\345\273\272\351\246\226\344\270\252Api.md" @@ -0,0 +1,25 @@ +## 创建首个Api + +1. 安装SDK + +2. Web的命令: + +- 新建一个WebApi项目:dotnet new webapi -n `命名` +- 新建一个解决方案:dotnet new sln -n `命名` +- 新建一个WebApi项目(--no -https参数表示不启用https):dotnet new webapi --no -https -o dream.WebApi +- 创建类库:dotnet new classlib -o `命名(dream.Entity)` + +3. 运行这个项目 +- dotnet run + +4. 在WeatherForecast.js中复制类名至导航栏,可看到数据 + +> 导航栏中localhost:端口/`swagger`可进入api的页面(CRUD) \ No newline at end of file -- Gitee From 346c183f4a40862f118f57a42a4b54ba8dd0c7b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=BB=BA=E7=A5=A5?= <958464639@qq.com> Date: Thu, 23 May 2024 17:37:54 +0800 Subject: [PATCH 2/3] 523 --- ...273\345\212\240\351\241\271\347\233\256.md" | 18 ++++++++++++++++++ ...235\350\265\226\346\263\250\345\205\245.md" | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 "\345\215\242\345\273\272\347\245\245/20240521-\350\247\243\345\206\263\346\226\271\346\241\210\357\274\214\345\274\225\347\224\250\346\267\273\345\212\240\351\241\271\347\233\256.md" create mode 100644 "\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" diff --git "a/\345\215\242\345\273\272\347\245\245/20240521-\350\247\243\345\206\263\346\226\271\346\241\210\357\274\214\345\274\225\347\224\250\346\267\273\345\212\240\351\241\271\347\233\256.md" "b/\345\215\242\345\273\272\347\245\245/20240521-\350\247\243\345\206\263\346\226\271\346\241\210\357\274\214\345\274\225\347\224\250\346\267\273\345\212\240\351\241\271\347\233\256.md" new file mode 100644 index 0000000..6e74774 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240521-\350\247\243\345\206\263\346\226\271\346\241\210\357\274\214\345\274\225\347\224\250\346\267\273\345\212\240\351\241\271\347\233\256.md" @@ -0,0 +1,18 @@ +## 解决方案,引用添加项目 +### 创建解决方案的sln文件 +1. 创建的命令 +- dotnet new sln -n `命名` +2. 添加项目的命令 +- dotnet sln add `项目文件夹` + +### 文件之间的引用 +- dotnet add `引用位置` reference `被引用文件` + +### 添加依赖包 +- dotnet add package `包名` + +### 还原文件 +- dotnew restore/build(优先) + +### 将项目跑起来 +- dotnet watct/run --project `文件位置` diff --git "a/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" "b/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" new file mode 100644 index 0000000..2c44bf9 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" @@ -0,0 +1,6 @@ +## api抽离、转换、依赖注入 +### 抽离 + +### 转换 + +### 依赖注入 \ No newline at end of file -- Gitee From a38f196e29ab85030ade86e4005312e4aeed0499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E5=BB=BA=E7=A5=A5?= <958464639@qq.com> Date: Sun, 26 May 2024 20:14:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?526=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...35\350\265\226\346\263\250\345\205\245.md" | 59 ++++++++++++++++++- ...72\346\216\247\345\210\266\345\231\250.md" | 58 ++++++++++++++++++ 2 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 "\345\215\242\345\273\272\347\245\245/20240524-api\345\210\233\345\273\272\346\216\247\345\210\266\345\231\250.md" diff --git "a/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" "b/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" index 2c44bf9..53e07ae 100644 --- "a/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" +++ "b/\345\215\242\345\273\272\347\245\245/20240523-api\346\212\275\347\246\273\343\200\201\350\275\254\346\215\242\343\200\201\344\276\235\350\265\226\346\263\250\345\205\245.md" @@ -1,6 +1,59 @@ ## api抽离、转换、依赖注入 -### 抽离 -### 转换 +- Program +```cs +namespace Admin.api; -### 依赖注入 \ No newline at end of file +public static class Program +{ + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + public static IHostBuilder CreateHostBuilder(string[] args) + { + return Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(builder=> + { + builder.UseStartup(); + }); + } +} +``` + +- Startup +```cs +namespace Admin.api; + +public class Startup +{ + public void Configure(IApplicationBuilder app) + { + app.UseRouting(); + app.UseEndpoints(endpoints =>{ + endpoints.MapControllers(); + }); + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } +} +``` + +- BlogController +```cs +using Microsoft.AspNetCore.Mvc; + +namespace Admin.api; + +[Route("[controller]")] + +public class BlogsController:ControllerBase +{ + public IActionResult Index() + { + return Ok("会了吗???"); + } +} +``` \ No newline at end of file diff --git "a/\345\215\242\345\273\272\347\245\245/20240524-api\345\210\233\345\273\272\346\216\247\345\210\266\345\231\250.md" "b/\345\215\242\345\273\272\347\245\245/20240524-api\345\210\233\345\273\272\346\216\247\345\210\266\345\231\250.md" new file mode 100644 index 0000000..034aee7 --- /dev/null +++ "b/\345\215\242\345\273\272\347\245\245/20240524-api\345\210\233\345\273\272\346\216\247\345\210\266\345\231\250.md" @@ -0,0 +1,58 @@ +## api创建控制器 +- Program +```cs +namespace Admin.api; + +public static class Program +{ + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + public static IHostBuilder CreateHostBuilder(string[] args) + { + return Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(builder=> + { + builder.UseStartup(); + }); + } +} +``` + +- Startup +```cs +namespace Admin.api; + +public class Startup +{ + public void Configure(IApplicationBuilder app) + { + app.UseRouting(); + app.UseEndpoints(endpoints =>{ + endpoints.MapControllers(); + }); + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } +} +``` + +- BlogController +```cs +using Microsoft.AspNetCore.Mvc; + +namespace Admin.api; + +[Route("[controller]")] + +public class BlogsController:ControllerBase +{ + public IActionResult Index() + { + return Ok("会了吗???"); + } +} +``` \ No newline at end of file -- Gitee