diff --git a/Admin1000/.gitignore b/Admin1000/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f5e2951b125989c06c9749408e4f50c5d04e497 --- /dev/null +++ b/Admin1000/.gitignore @@ -0,0 +1,13 @@ +# 针对可能的编辑器的设置 +.vscode +.vs + + +# 针对后端asp.net core api项目的设置 +bin +debug +obj + + +# 针对前端vue项目的设置 +node_modules \ No newline at end of file diff --git a/Admin1000/Admin1000.Backend/Admin1000.Backend.csproj b/Admin1000/Admin1000.Backend/Admin1000.Backend.csproj new file mode 100644 index 0000000000000000000000000000000000000000..d12c450b7be925549ec1738db82e35481fa8cbbc --- /dev/null +++ b/Admin1000/Admin1000.Backend/Admin1000.Backend.csproj @@ -0,0 +1,8 @@ + + + + netcoreapp3.1 + + + + diff --git a/Admin1000/Admin1000.Backend/Admin1000.Backend.sln b/Admin1000/Admin1000.Backend/Admin1000.Backend.sln new file mode 100644 index 0000000000000000000000000000000000000000..2f92ebd9bda9292e2c0238f7ef2c03e5e1a019a9 --- /dev/null +++ b/Admin1000/Admin1000.Backend/Admin1000.Backend.sln @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Admin1000/Admin1000.Backend/Controllers/WeatherForecastController.cs b/Admin1000/Admin1000.Backend/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000000000000000000000000000000000000..9cebc99b84c6d1ccaabee33a09b0bb1eb5523551 --- /dev/null +++ b/Admin1000/Admin1000.Backend/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace Admin1000.Backend.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Admin1000/Admin1000.Backend/Program.cs b/Admin1000/Admin1000.Backend/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..356a7ea3be78f83e8cdaca3129ea9b50b207b41b --- /dev/null +++ b/Admin1000/Admin1000.Backend/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Admin1000.Backend +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Admin1000/Admin1000.Backend/Properties/launchSettings.json b/Admin1000/Admin1000.Backend/Properties/launchSettings.json new file mode 100644 index 0000000000000000000000000000000000000000..ae135b9df7b9060014ff92477a1de2637e0feaf7 --- /dev/null +++ b/Admin1000/Admin1000.Backend/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:33781", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Admin1000.Backend": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Admin1000/Admin1000.Backend/Startup.cs b/Admin1000/Admin1000.Backend/Startup.cs new file mode 100644 index 0000000000000000000000000000000000000000..0c73ef668d4fe84556f0e666124811720be914a8 --- /dev/null +++ b/Admin1000/Admin1000.Backend/Startup.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Admin1000.Backend +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Admin1000/Admin1000.Backend/WeatherForecast.cs b/Admin1000/Admin1000.Backend/WeatherForecast.cs new file mode 100644 index 0000000000000000000000000000000000000000..9527bb1af658e09c6be92894ff7503e918176c65 --- /dev/null +++ b/Admin1000/Admin1000.Backend/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace Admin1000.Backend +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/Admin1000/Admin1000.Backend/appsettings.Development.json b/Admin1000/Admin1000.Backend/appsettings.Development.json new file mode 100644 index 0000000000000000000000000000000000000000..8983e0fc1c5e2795ccfde0c771c6d66c88ef4a42 --- /dev/null +++ b/Admin1000/Admin1000.Backend/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Admin1000/Admin1000.Backend/appsettings.json b/Admin1000/Admin1000.Backend/appsettings.json new file mode 100644 index 0000000000000000000000000000000000000000..d9d9a9bff6fd6f3ee7ea00de958f135a4a28c6e6 --- /dev/null +++ b/Admin1000/Admin1000.Backend/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Admin1000/admin1000.frontend b/Admin1000/admin1000.frontend new file mode 160000 index 0000000000000000000000000000000000000000..a83045343d84b09ea52b3cd75abe60efb46f3c00 --- /dev/null +++ b/Admin1000/admin1000.frontend @@ -0,0 +1 @@ +Subproject commit a83045343d84b09ea52b3cd75abe60efb46f3c00 diff --git "a/\351\237\251\345\235\244/2021-6-16(\350\267\257\347\224\261).md" "b/\351\237\251\345\235\244/2021-6-16(\350\267\257\347\224\261).md" new file mode 100644 index 0000000000000000000000000000000000000000..a2df607c15492a5d9fd2894a652219d42845bfb3 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-16(\350\267\257\347\224\261).md" @@ -0,0 +1,56 @@ +# 动态路由匹配 + +`Profile.vue` +``` + +``` +``` +export default { + data:function(){ + return { + + } + },mounted:function(){ + console.log(this.$route.params.carname); + } +} +``` + +`main.js` +``` +let router=new VueRouter({ + mode:'history', + routes:[ + { + path:'/profile/:carname', + component:Profile + },{ + path:'*', + component:all + } + ] +}) +``` + +`all.vue` +``` + + +``` + +输入http://localhost:8080/profile/(任意值)都可以显示Profile.vue的页面,否则都是显示all.vue \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-18.md" "b/\351\237\251\345\235\244/2021-6-18.md" new file mode 100644 index 0000000000000000000000000000000000000000..71a440cffc97431bdede4bd473fd11683a1d8138 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-18.md" @@ -0,0 +1,46 @@ +## 编程式导航 +除了使用 创建 a 标签来定义导航链接,我们还可以借助 router 的实例方法,通过编写代码来实现。 + +router.push(location) + + 想要导航到不同的 URL,则使用 router.push 方法。这个方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,则回到之前的 URL。 + + 当你点击 时,这个方法会在内部调用,所以说,点击 等同于调用 router.push(...)。 + + 该方法的参数可以是一个字符串路径,或者一个描述地址的对象。例如: + + + // 字符串 + router.push('home') + + // 对象 + router.push({ path: 'home' }) + + // 命名的路由 + router.push({ name: 'user', params: { userId: 123 }}) + + // 带查询参数,变成 /register?plan=private + router.push({ path: 'register', query: { plan: 'private' }}) + +router.replace(location) + 跟 router.push 很像,唯一的不同就是,它不会向 history 添加新记录,而是跟它的方法名一样 —— 替换掉当前的 history 记录。 + +router.go(n) + 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n)。 + + + // 在浏览器记录中前进一步,等同于 history.forward() + router.go(1) + + // 后退一步记录,等同于 history.back() + router.go(-1) + + // 前进 3 步记录 + router.go(3) + + // 如果 history 记录不够用,那就默默地失败呗 + router.go(-100) + router.go(100) + + + ``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-19(\345\221\275\345\220\215\350\267\257\347\224\261).md" "b/\351\237\251\345\235\244/2021-6-19(\345\221\275\345\220\215\350\267\257\347\224\261).md" new file mode 100644 index 0000000000000000000000000000000000000000..6727fb78fb81e8bb3d60cc288bb07efc0c899140 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-19(\345\221\275\345\220\215\350\267\257\347\224\261).md" @@ -0,0 +1,77 @@ + +## 命名路由 + +顾名思义,给路由一个命名,可以通过命名来做一些操作 ++ 不能把命名当成路径访问 ++ 可以用作``中 +``` +path: '/car', + name: 'car', + components: { + car: Car, +} +``` +## 命名视图 + +可以用于同时(同级展示多个视图,不是嵌套展示) + +``` +routes: [{ + path: '/user', + name: 'user', + components: { + user: User, + register: Register, + login: Login + } +``` +在`/user`路径,可以通过路由的命名来显示多个路由(需要在app.vue中创建视图: +``` +
+ + + + + + + +
+``` +) + +### 嵌套命名视图 +在命名视图的基础上,进行嵌套的操作 + +``` +{ + path: '/car', + name: 'car', + components: { + car: Car, + + },children:[{ + path:'audi', + component:Audi + },{ + path:'bmw', + components:{ + bmw:BMW + } + }] + } +``` +需要在父路由(Car.vue)里引用子路由的视图: +``` +
+ + + +

阿坤车行

+ 去看看宝马 + 去看看奥迪 +
+ +
+``` + +## 重定向 \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-22(web Api).md" "b/\351\237\251\345\235\244/2021-6-22(web Api).md" new file mode 100644 index 0000000000000000000000000000000000000000..35631a7f1eb63aca007b840ce67f5ca12dc71c3c --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-22(web Api).md" @@ -0,0 +1,45 @@ +# web api创建项目 +1. 创建.net core解决方案 +``` +//名称Dream + dotnet new sln -o Dream +``` +2. 进入解决方案 +``` +cd Dream + +查看文件 +ls +``` +3. 创建webApi项目 +``` +//webapi表示创建项目时选择模板的类型 +//--no-https表示不启用https +dotnet new webapi --no-https -o Dream.WebApi +``` +4. 创建类库项目 +``` +//Dream.Entity和Dream.Service是类库名称 +//classlib表示类库模板 + dotnet new classlib -o Dream.Entity + dotnet new classlib -o Dream.Service +``` +5. 将项目添加至解决方案 +``` + dotnet sln Dream.sln add Dream.WebApi/Dream.WebApi.csproj Dream.Entity/Dream.Entity.csproj Dream.Service/Dream.Service.csproj +``` +6. 目前项目基本创建好,但是我们实际当中还涉及到项目之间的引用,这里我们的 “Dream.Service”项目需要引用“Dream.Entity”项目,“Dream.WebApi”项目需要引用“Dream.Entity”和“ Dream.Entity ”两个项目,我们接着继续进行项目之间的引用操作,命令如下,命令当中“ reference ”参数就是起引用作用 +``` +> dotnet add Dream.Service/Dream.Service.csproj reference Dream.Entity/Dream.Entity.csproj +> dotnet add Dream.WebApi/Dream.WebApi.csproj reference Dream.Service/Dream.Service.csproj Dream.Entity/Dream.Entity.csproj +``` +7. 引用NuGet软件包到项目中 +``` +//package参数是引用NuGet包的作用 + dotnet add Dream.WebApi/Dream.WebApi.csproj package Newtonsoft.Json +``` +8. 运行项目 +``` +//-p是指要运行的项目 + dotnet run -p Dream.WebApi/Dream.WebApi.csproj +``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-23.md" "b/\351\237\251\345\235\244/2021-6-23.md" new file mode 100644 index 0000000000000000000000000000000000000000..a0fe8fe00ad5d1b12760881858ec156a85aa86a0 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-23.md" @@ -0,0 +1,169 @@ +API的第二次课 在WebApi中进行增删改查 + +1. 创建一个文件夹MyApp 打开 创建解决方案 +``` +dotnet new sln -n +创建一个WebApi并且有安全证书 +dotnet new webapi -n MyApp.WebApi --no-https + +安装拓展 +以下拓展增加提示 减少代码量 +C# Extensions +C# XML Documentation Comments +Better Comments +Prettier - Code formatter +通过一个 VSCOde界面来展示响应的界面内容 并在发送路径中给予提示 +REST Client +``` +2. 创建一个 app.http 来写下webapi运行时端口发送获得响应 即自定义的增删改查(post delete put get) +``` +### 查询全部用户 +GET http://localhost:5000/users HTTP/1.1; + +### 查询指定用户 +GET http://localhost:5000/users/2 HTTP/1.1 + + +### 创建用户 +POST http://localhost:5000/users HTTP/1.1 +Content-Type: application/json + +{ + "username":"地牢", + "password":"五个专属箱子" +} + +### 修改指定用户 +PUT http://localhost:5000/users/1 HTTP/1.1 +Content-Type: application/json + +{ + "username":"地牢", + "password":"五个专属箱子" +} + +#### 删除用户 +DELETE http://localhost:5000/users/2 HTTP/1.1 +``` +3. 在WebAPi中创建一个Entity文件夹 在内创建一个用户表cs文件 +namespace 是在WebAPi中的位置 +``` +using System;//为了调用DateTiem方法 定义用户表的数据库结构并定义创建时间和更新时间的默认值和备注的默认值 + + +namespace MyApp.WebApi.Entity +{ + public class Users{ + public Users() + { + CreateTime = DateTime.Now; + UpdateTime = DateTime.Now; + Remarks = ""; + } + + +public int Id { get; set; } + +public string UsersName { get; set; } + +public string Password { get; set; } + +public DateTime CreateTime { get; set; } + +public DateTime UpdateTime { get; set; } + +public string Remarks { get; set; } +} +} +``` +4. 在WebApi中Controllers中定义一个UsersControllers 来定义响应界面的内容 dynamic (自动辨别变量的类型) +``` +using Microsoft.AspNetCore.Mvc;//调用Mvc(model view controller )的方法 +using System.Collections.Generic;//调用集成式的泛型数组 +using MyApp.WebApi.Entity;//调用定义的Entity的用户表结构 +using System.Linq;//为了调用数据可中的Where 等方法 + +namespace MyApp.WebApi.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + //参照WebApi中已存在的WeatherForecastControllers 书写 + { + //获取所有定义的用户 + [HttpGet] + public dynamic Get() + { + var users = GetUsers(); + return users; + } + + //获取指定id的用户信息 + [HttpGet("{id}")] + public dynamic Get(int id) + { + var users = GetUsers(); + var user = users.Where(x => x.Id == id).FirstOrDefault(); + return user; + } + + //创建用户 + [HttpPost] + public dynamic Get(dynamic model) + { + return new + { + Code = 1000, + Data = model, + Msg = "创建一个用户成功" + }; + } + + //修改指定用户 + [HttpPut("{id}")] + public dynamic Put(int id,dynamic model){ + return new { + Code =1000, + Data=model, + Msg =string.Format("你修改的是用户id为:{0}",id) + }; + } + + //删除用户 + [HttpDelete] + public dynamic Delete(int id){ + return new { + Code =1000, + Msg =string.Format("你删除的用户id为:{0}",id) + }; + } + + //写一个私人的泛型集成式数组来进行调用定义好的用户信息 + private IEnumerable GetUsers() + { + var users = new List{ + new Users{ + Id=1, + UsersName="神圣地", + Password="shensheng" + }, + new Users{ + Id=2, + UsersName="腐地", + Password="fudi" + }, + new Users{ + Id=3, + UsersName="血腥之地", + Password="xuexing" + } + }; + return users; + } + + + + + } +} +``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-25.md" "b/\351\237\251\345\235\244/2021-6-25.md" new file mode 100644 index 0000000000000000000000000000000000000000..bbe95eac6014111b2044902bad56a12ea35e6a8d --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-25.md" @@ -0,0 +1,27 @@ +# ef core创建控制台应用 +1. 创建一个webapi项目 +2. 安装Entity Franmework Core +``` +dotnet add package Microsoft.EntityFrameworkCore.Sqlserver +``` +3. 创建一个模型 +``` + public class BloggingContext : DbContext + { + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } + + // The following configures EF to create a Sqlite database file as `C:\blogging.db`. + // For Mac or Linux, change this to `/tmp/blogging.db` or any other absolute path. + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite(@"Data Source=C:\blogging.db"); + } +``` +使用迁移创建数据库 +``` +dotnet tool install --global dotnet-ef +dotnet add package Microsoft.EntityFrameworkCore.Design +dotnet ef migrations add InitialCreate +dotnet ef database update +这会安装 dotnet ef 和设计包,这是对项目运行命令所必需的。 migrations 命令为迁移搭建基架,以便为模型创建一组初始表。 database update 命令创建数据库并向其应用新的迁移。 +``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-6-29.md" "b/\351\237\251\345\235\244/2021-6-29.md" new file mode 100644 index 0000000000000000000000000000000000000000..4dead48f3ae9c1f0145049501858c8e07c6965fd --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6-29.md" @@ -0,0 +1,55 @@ +封装一下表结构创建一个BaseModel.cs 定义基础属性 让创建的用户表等继承: + +1. 包装一下Entity下的.cs的公共字段 创建BaseEntity.cs + +``` +using System; +namespace MyApi.Api.Entity +{ + public abstract class BaseEntity{ + public BaseEntity(){ + CreatedTime=DateTime.Now; + UpdatedTime=DateTime.Now; + } + public int Id{get;set;} + public bool IsActived{get;set;} + public bool IsDeleted{get;set;} + public DateTime CreatedTime{get;set;} + public DateTime UpdatedTime{get;set;} + public string Remarks{get;set;} + } +} + +如:在Users.cs定义字段下继承 public class Users : BaseEntity +``` + +2. 建立表之间的关系 Entity文件夹下 +``` +Users.cs + public class Users : BaseEntity + { + public string Username { get; set; } + + public string Password { get; set; } + + public virtual IEnumerable UserRoles { get; set; } + + } + +UserRoles.cs + public class UserRoles : BaseEntity + { + public int UserId { get; set; } + public int RoleId { get; set; } + public virtual Users User { get; set; } + public virtual Roles Role { get; set; } + } + +Roles.cs + public class Roles:BaseEntity + { + public string RoleName { get; set; } + public virtual IEnumerable UserRoles { get; set; } + } +``` + diff --git "a/\351\237\251\345\235\244/2021-6.30.md" "b/\351\237\251\345\235\244/2021-6.30.md" new file mode 100644 index 0000000000000000000000000000000000000000..a4bf77f4a1c20e896d0e9434d4f15da2aedde371 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-6.30.md" @@ -0,0 +1,14 @@ +## AsQueryable() ++ 将一个序列向下转换为一个IQueryable, 它生成了一个本地查询的IQueryable包装。 +``` +var products = db.Product.where(p => p.Type == "food").select(p => new { p.Id, p.Name, p.CreateTime}); +``` ++ Select() 的返回类型为 IQueryable,为 IQueryable, 语句执行后不会立刻查询数据库, 而是在迭代使用 products 时才会查数据库, 具有 lazy load 的特性, 按需查数据库可提高程序效率。 + +## NullReferenceException() ++ 如果对象是空的将会调用该方法。 + +## 关于Task返回值 ++ Task async await本来就是三位一体的缺少任何其中一个,那么是无法编译,要么就还是一个同步方法,实现不了异步功能 ++ Task fun()就是一个同步方法,返回值是Task,而不是T ++ async Task fun(){ await xxx } ,是异步的,返回的是T,而不是Task \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-7-2.md" "b/\351\237\251\345\235\244/2021-7-2.md" new file mode 100644 index 0000000000000000000000000000000000000000..9b2abe46e2365df57a6eb5653899f721dbb822a4 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-7-2.md" @@ -0,0 +1,26 @@ +# web API web API第六节 使用依赖注入 + +`dotnet restore -恢复项目的依赖项和工具` + +1. Startup.cs +``` + public void ConfigureServices(IServiceCollection services) + { + // 注册数据库上下文到容器 + services.AddDbContext(o =>o.UseSqlServer()); + // 注册对数据库的基本操作服务到容器 + services.AddScoped(typeof(IRepository<>),typeof(EfRepository<>)); + + services.AddControllers(); + } +``` + +2. UsersController.cs引用 +``` +private IRepository _usersRepository; + +public UserController(IRepository usersRepository) +{ + _usersRepository=usersRepository; +} +``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/2021-7-3.md" "b/\351\237\251\345\235\244/2021-7-3.md" new file mode 100644 index 0000000000000000000000000000000000000000..6858740ad5e528bf6fd217250989b8869d44e1c7 --- /dev/null +++ "b/\351\237\251\345\235\244/2021-7-3.md" @@ -0,0 +1,65 @@ +# 回顾C#基础 + +## 接口 ++ 什么是接口? +``` +定义一个对象,不实现给他定义的属性,只能由类和结构实现 +``` ++ 接口的作用 +``` +定义一些特有的行为 +``` ++ 怎么用 +``` +interface IMyInterface //interface 是关键字,后面的是接口名称 +{ + int DoSomething(int val1, int val2); //分号代表实现主体,不能含有public等修饰符,默认为public +} +使用类去继承(实现)接口 +``` +## 泛型 ++ 什么是泛型 +``` +一些动物有一个共同的点(走,叫),在这里,走、叫可以被称作为泛型 +``` ++ 泛型的作用 +``` + 定义 一种自动辨别数据类型的变量 +C# 泛型 作用 用来将自己定义的一些属性或者说是一个方法通过被 定义的 类继承来调用接口中的属性或者说是定义完善接口中的方法体 并添加上 在变量后 如IPeople + 用法 public interface IPerson{ + void Eat(T thing); + } + public class Animals:IPerson{ + public void Eat(T thing){ + System.Console.WriteLine(”打印一些东西“) + } + } + +``` + +``` + 属性 具有get(获取变量的返回值) set(定义变量 条件约束变量) + 属性 类的成员 方法 形如 public class people(方法名称){//构造函数(定义变量等在运行时就定义完成) public people(方法名称)} + 字段 定一个字段作为变量并赋值 public int Id + 自动属性 只需要一个属性 不需要再去定义字段来获取value + public string str{get;set;}= private string _str; + public string str{ + get{ + return _str + } ;set{ + _str=value + } +``` + +``` +dotnet new sln -n App +dotnet new web.api -n App.Web.Api +cd .. +dotnet sln App add App.Web.Api +dotnet add package Microsoft.EntityFrameworkCore +dotnet add package Microsoft.EntityFrameworkCore.SqlServer +dotnet add package Microsoft.EntityFrameworkCore.Design +dotnet tool install --global dotnet-ef +dotnet ef migrations add XX +dotnet ef database update +``` \ No newline at end of file diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-0-11.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-0-11.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..702a16ab1721a5dc8a305e84a8c0d7a7135feef1 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-0-11.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-11-12.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-11-12.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..c78844b617ce109349caf08494a0c6a88635c998 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-11-12.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-18-37.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-18-37.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..2482277f4479019194d1c1303d1791842590f904 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-18-37.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-20-19.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-20-19.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..96d8fd6ec5227f39e72e7a30e1e142627dbc538f Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-20-19.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-25-40.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-25-40.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..f41fb4802ba7e4f99105bd99c64fbcc899cf5951 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-25-40.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-27-47.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-27-47.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..199cd4856d659ad9854a0c8b8479e5eda808a743 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-27-47.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-3-12.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-3-12.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..e870dd796f819b46703f7e80d23e0457df73376e Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-3-12.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-32-42.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-32-42.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..12d9f98fa4a2d9f085cba9be13e6473bc64a33c7 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-32-42.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-36-38.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-36-38.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..e9c1bd015883002081f02e75780a993d9c60469b Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-36-38.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-38-0.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-38-0.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..b00a14908c59af921aa73b7920e38a0511119e35 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-38-0.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-2.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-2.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..f4e0489408929914d5196d57d0e02830096aa861 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-2.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-38.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-38.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..5121482dd1b36b1a57cd408571da179b4417fa1c Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-5-38.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-6-49.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-6-49.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..32d32b1bc5bcee90df2aa3754324df7e8e30e75c Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-6-49.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-9-2.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-9-2.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..f87e779e64d9195d277a5d626d43c924be3e262e Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 15-9-2.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-23.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-23.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..fb7eaddfbf2af90c9d2b7530052f00241d960ddf Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-23.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-5.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-5.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..31c4188b3cf2cb6b523041245e0d1a2692b24c0a Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-12-5.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-14-34.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-14-34.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..c8ae38d69067e7e1fddc9dc085d5b3af1ffce4b0 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-14-34.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-4-59.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-4-59.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..bc9da240e187e84d48bfcd30a2145f9555d32d30 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-4-59.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-8-26.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-8-26.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..e1a07a8c6ba0899acf66d9ae462152f7fcaaf464 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-8-26.JPG" differ diff --git "a/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-9-34.JPG" "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-9-34.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..4bd111ef5b00481af0cccbfab90d8f14cf7349b9 Binary files /dev/null and "b/\351\237\251\345\235\244/img/6.26web api\346\210\252\345\233\276/2021-6-26 16-9-34.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-33-56.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-33-56.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..59769eabc7f3d20a8203dc786721fd0c05119eec Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-33-56.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-35-50.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-35-50.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..29ba3ea0b4447fecf7089d44c847486f1c1caa8a Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-35-50.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-38-31.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-38-31.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..d8f91f7119108b039b54735b6499c20ef2c89e03 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-38-31.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-41-59.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-41-59.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..ab3def17e83dcb6b012482609c635d93ef04fd6a Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-41-59.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-42-56.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-42-56.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..d34e44d028681b52fc27b3470a6eab425b8d43c5 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-42-56.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-45-22.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-45-22.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..4bdf43efa3cba5d992d05d8e0bff250217091009 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-45-22.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-46-51.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-46-51.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..4b82d2faa65775c7aa56f221ebcf090dada5377d Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-46-51.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-49-25.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-49-25.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..bc03d71e71036dcd264079a873ad6ecab9c43053 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 14-49-25.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-15-13.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-15-13.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..6943b5f2c93ba407ab625ddf9b21eb991a1add37 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-15-13.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-19-40.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-19-40.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..f701e296632b9bb2cf7ab1d50ba4c5b5fa7c80fe Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-19-40.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-24-46.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-24-46.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..91a70247dbfe2eee0cddfa94396b23fe42bd6c77 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-24-46.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-23.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-23.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..ee19e1c724ef6f72d09e7db6ae60b736ca2caf22 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-23.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-55.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-55.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..84015d5b91e2ea772aa8121d6d19a6577e4084d4 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-27-55.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-30-41.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-30-41.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..34b21939768fe43bcaf28529becc2d384e443de6 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-30-41.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-32-45.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-32-45.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..ffac61f44febfaa4ef2813fc0ec9737f269054cd Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-32-45.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-36-10.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-36-10.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..8e344c5f7ea19411766492ff12200f9f6010ab90 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-36-10.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-37-35.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-37-35.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..aa7378775260e2c5c085038cf5856f61b0c08ea0 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-37-35.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-38-40.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-38-40.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..e9cd91f651860cafa0f1329fa98a27ef05fa0a13 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-38-40.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-39-19.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-39-19.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..f49dc297798cb9e9ef1eb489770c12b87b41a084 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-39-19.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-45-12.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-45-12.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..259831b25847e968b11877800e0e548032f05507 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-45-12.JPG" differ diff --git "a/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-7-56.JPG" "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-7-56.JPG" new file mode 100644 index 0000000000000000000000000000000000000000..82d08d2ab679941d0fc121e78e571e3bfb9f9db1 Binary files /dev/null and "b/\351\237\251\345\235\244/img/wei Api/2021-6-23 15-7-56.JPG" differ