diff --git "a/\351\231\210\346\243\256/Vue.2021-06.21.md" "b/\351\231\210\346\243\256/WebApi.2021-06.21.md" similarity index 82% rename from "\351\231\210\346\243\256/Vue.2021-06.21.md" rename to "\351\231\210\346\243\256/WebApi.2021-06.21.md" index bbe96f38012a86ad9c5eae7a66d889377ccab86b..fd39b97b601512ff5a2be3c86d959aa8635ccdac 100644 --- "a/\351\231\210\346\243\256/Vue.2021-06.21.md" +++ "b/\351\231\210\346\243\256/WebApi.2021-06.21.md" @@ -25,9 +25,22 @@ dotnet sln add Api.Domian dotnet restore 命令 还原项目包 + +搭建wqebapi项目连接数据库: +dotnet new sln -n MyTest.Api +dotnet new webapi -n MyTest.Api --no-https +dotnet sln add MyTest.Api .Api +cd MyTest.Api +dotnet add package Microsoft.EntityFrameworkCore +dotnet add package Microsoft.EntityFrameworkCore.SqlServer +dotnet tool install --global dotnet-ef +dotnet add package Microsoft.EntityFrameWorkCore.Design +(定义实体模型、定义数据库上下文,定义连接字符串) +dotnet ef migrations add XXX +dotnet ef database update + ``` -常用命令 -![](./imgs/999.png) + #### 编写批处理文件一键生成框架 diff --git "a/\351\231\210\346\243\256/WebApi.2021-06.22.md" "b/\351\231\210\346\243\256/WebApi.2021-06.22.md" new file mode 100644 index 0000000000000000000000000000000000000000..268656bd7abb61155767e8ef2fe68e730f2111c8 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-06.22.md" @@ -0,0 +1,144 @@ +### dotnet创建Api项目并实现restfull风格的接口和测试 +``` +在商店下载扩展:c#Extensions ,C#XML ,REST Client + +创建Entity文件夹Users.cs的属性: + + +namespace Mytest.Api.Entity +{ + public class Users{ + public int Id {get;set;} + public string Username {get;set;} + public string PassWord {get;set;} + + } +} + +创建一个新的控制器文件:UsersControllers.cs +using Microsoft.AspNetCore.Mvc; +using Mytest.Api.Entity; +using System.Collections.Generic; +namespace Mytest.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + { + public IEnumerable Get() //接口继承 + { + var users=new List + { + new Users{ + Id=1, + Username="dog", + PassWord="113" + + }, + new Users{ + Id=2, + Username="jeck", + PassWord="116" + + },new Users{ + Id=3, + Username="mioke", + PassWord="119" + + }, + }; + return users; + } + [HttpGet("{id}")] + public string get(int id) + { + return string.Format("你的ID是:{0}", id); + } + } + +} + public dynamic Post(dynamic model) + { + + return new + { + Code = 1000, + Data = model, + Msg = "请求成功" + }; + } + [HttpPut("{id}")] + public dynamic Put(int id, dynamic model) + { + + return new + { + Code = 1000, + Data = string.Format("修改的id为:{0}", id), + + Msg = "修改成功" + }; + } + + + [HttpDelete("{id}")] + public dynamic Delete(int id) + { + return new + { + Code = 1000, + Data = string.Format("删除的id为:{0}", id), + + Msg = "删除成功" + }; + + + } + + + + +``` +### 测试下载 REST Client 进行链接测试 +``` +创建一个.http/.rest为后缀的文件进行测试 +### 为一个新的Send Request 点击测试 + +GET https://localhost:5001/WeatherForecast HTTP/1.1 + +### get请求 +GET https://localhost:5001/Users +### +GET https://localhost:5001/Users/60 + +### post请求 +Post https://localhost:5001/Users +Content-Type:application/json +//这里必须空一行 + +{ + "username":"青青草原羊", + "password":"111" +} + +### put请求,用于修改 +PUT https://localhost:5001/Users/12 +Content-Type:application/json + +{ + + "username":"狼堡小灰灰", + "password":"111" +} + +### delete用于删除 +DELETE https://localhost:5001/Users/33 + + +把项目跑起来就可以进行测试了(dotnet run Mytest.Api ) + + + +``` +![](./imgs/3.png) + diff --git "a/\351\231\210\346\243\256/WebApi.2021-06.24.md" "b/\351\231\210\346\243\256/WebApi.2021-06.24.md" new file mode 100644 index 0000000000000000000000000000000000000000..84551c6c66fc055a0ddae9bb4c89f689c49becd3 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-06.24.md" @@ -0,0 +1,104 @@ +### 使用dotnet连接数据库SQLite +``` +使用Navicat Premium 进行测试,使用SQLite数据库的原因是,它可在.NET Core支持的所有平台上运行. + +新建get查询: + public IEnumerable Get(string cou, int pageIndex=1,int pageSizx=5)//(关键词,分页,页面大小) + { + var users = GetUsers().Where(x=>x.Username.Contains(cou)).Skip((pageIndex-1)*pageSizx).Take(pageSizx); + return users; + + } + public dynamic Get(int id) + { + var user = GetUsers().Where(x=>x.Id==id).FirstOrDefault(); + return new + { + Code = 1000, + Data = user, + Msg = "查询成功" + + }; + } + private IEnumerable GetUsers() + { + var count = 50; + var users = new List(); + for (var i = 1; i <= count; i++) + { + var u = new Users + { + Id =i, + Username = string.Format("猪猪{0}号", i), + PassWord = string.Format("密码{0}号", i), + + }; + users.Add(u); + } + return users; + + + + } + + +``` +### EF Core +``` +安装包dotnet add package Microsoft.EntityFrameworkCore.Sqlite + +新建数据库模型: +新建Databasae文件夹UserDb.cs为数据库上下文: +using Microsoft.EntityFrameworkCore; +using Mytest.Api.Entity; + +namespace Mytest.Api.Db +{ + public class UserDb:DbContext + { + public DbSetUsers{get;set;} + public DbSetUsersRoles{get;set;} + public DbSetRoles{get;set;} + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite(@"Data Source=C:\blogging.db"); //生成一个数据库文件,拿来测试 + + + } +} + +创建模型类为默认表: + public class Roles + { + public int Id {get;set;} + public int RolesName {get;set;} + public DateTime CreatedTime {get;set;} + public DateTime UpdateTime {get;set;} + } + + public class UserRoles + { + public int Id { get; set; } + public int UserId{ get; set; } + public int RolesId { get; set; } + } + public class Users{ + public int Id {get;set;} + public string Username {get;set;} + public string PassWord {get;set;} + + } + +创建数据库: +dotnet tool install --global dotnet-ef +dotnet add package Microsoft.EntityFrameworkCore.Design +dotnet ef migrations add InitialCreate +dotnet ef database update + +``` +### Rest Client 测试 +``` +### get请求,用于列出指定的用户 +GET https://localhost:5001/Users?pageIndex=1&pageSize=5&cou=1 +### get请求,用于查找id +GET https://localhost:5001/Users/22 +``` \ No newline at end of file diff --git "a/\351\231\210\346\243\256/WebApi.2021-06.26.md" "b/\351\231\210\346\243\256/WebApi.2021-06.26.md" new file mode 100644 index 0000000000000000000000000000000000000000..b213a8abc27034161ae10894a6e290f02c29d1fa --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-06.26.md" @@ -0,0 +1,67 @@ +### sqlite生成User表数据,和注入依赖 +``` +开始前的准备: +dotnet restore +dotnet tool install --global dotnet-ef +dotnet ef database update + +UsersControllers.cs: +using Mytest.Api.Db;//引入数据库上下文 + + +为User创建默认数据表: + +public class UsersController : ControllerBase + { + private UserDb _db; + + + public UsersController(UserDb db) + { + _db=db; + } + public IEnumerable Get(string cou, int pageIndex=1,int pageSizx=5) + { + _db.Users.Add(new Users + { + Username="admin", + PassWord="113" + + }); + _db.AddRange( new List + { + new Users + { + Username="111", + PassWord="111" + }, + new Users + { + Username="333", + PassWord="333" + }, + new Users + { + Username="222", + PassWord="222" + }, + }); + _db.SaveChanges(); + var users = GetUsers().Where(x=>x.Username.Contains(cou)).Skip((pageIndex-1)*pageSizx).Take(pageSizx); + return users; + + } +当项目跑起来运行:GET https://localhost:5001/Users 返回表数据 +然后进行dotnet ef database update 数据更新 + +依赖注入:在Startup.cd下 + public void ConfigureServices(IServiceCollection services) + { + services.AddScoped(); + services.AddControllers(); + } + //这个方法将在程序运行时调用,方法将服务添加到容器 + +``` ++ 理解依赖注入:https://www.cnblogs.com/jesse2013/p/di-in-aspnetcore.html ++ 官方版本:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0 diff --git "a/\351\231\210\346\243\256/WebApi.2021-06.28.md" "b/\351\231\210\346\243\256/WebApi.2021-06.28.md" new file mode 100644 index 0000000000000000000000000000000000000000..3f847de0f5263dce274af83add2bce31314b8282 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-06.28.md" @@ -0,0 +1,122 @@ +### 使用sqlserver数据库进行表生成和创建组外键关系 +``` +新建解决方法和Api: +dotnet new sln +dotnet new webapi -n Myapp-Api --no-https +dotnet sln add Myapp-Api + + +安装ef core 包: +dotnet tool install --global dotnet-ef +dotnet add package Microsoft.EntityFrameworkCore.Design +dotnet ef migrations add 数据迁移 +dotnet ef database update //数据更新 + +安装SQL server依赖包: +dotnet add package Microsoft.EntityFrameworkCore.SqlServer +dotnet add package Microsoft.EntityFrameworkCore + + +添加连接字符串 +在appsettings.json文件添加连接信息 +"ConnectionStrings": + { + "SqlServerConnection":"Server=.;Database=ApiTest;uid=sa;pwd=123456;" + } + +Startup.cs添加: + public void ConfigureServices(IServiceCollection services) + { + var sqlConnection = Configuration.GetConnectionString("SqlServerConnection"); + + services.AddDbContext(option => option.UseSqlServer(sqlConnection)); + services.AddControllers(); + + } + + + dotnet ef database drop //删库跑路 + dotnet ef migrations remove //删除迁移 + dotnet ef migrations add ... //添加迁移 + dotnet ef database update //关系数据 + + +``` +### 数据库模型类 +``` +新建数据库模型: +新建Databasae文件夹MyappDb.cs为数据库上下文: +using Microsoft.EntityFrameworkCore; +using Mytest.Api.Entity; + +namespace Myapp.Api.DataBase +{ + public class MyappDb : DbContext + { + public MyappDb(DbContextOptions options) : base(options) + { + + } + public DbSet Users { get; set; } + public DbSet Roles { get; set; } + public DbSet UserRoels { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + options.UseSqlServer(@"server=.;database=PPP;uid=sa;pwd=123456;"); + } + + } + + +} + +创建模型类: +新建一個抽象类:BaseEntity.cs +using System; +namespace Myapp.Api.Entity +{ + public abstract class BaseEntity + { + public int Id{get;set;} + public bool IsActived { get; set; } + public bool IsDeleted { get; set; } + public DateTime CreatedTime { get; set; } + public DateTime DeleteTime { get; set; } + public int DisplayDrder { get; set; } + public String Remarks { get; set; } + } + +} + + public class Roles:BaseEntity + { + public string RoelsName{get;set;} + public virtual IEnumerable UserRoles { get; set; } + } + + + + public class UserRoels:BaseEntity + { + public int UserId { get; set; } + public int RoleId { get; set; } + + public virtual Users User { get; set; } + public virtual Roles Roel { get; set; } + } + + + + + + + public class Users :BaseEntity + { + public string Username { get; set; } + public string Password { get; set; } + + public virtual IEnumerable UserRoels { get; set; } + } + +``` \ No newline at end of file diff --git "a/\351\231\210\346\243\256/WebApi.2021-06.29.md" "b/\351\231\210\346\243\256/WebApi.2021-06.29.md" new file mode 100644 index 0000000000000000000000000000000000000000..d65927b8c642b9dc6324def1214ad8f81ca73d08 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-06.29.md" @@ -0,0 +1,203 @@ +### 数据库的增删改查(CRUD) +``` +新建文件夹:IResop +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Myapp.Api.Entity; +namespace Myapp.Api.IResop +{ + //定义一个接口,用来实体类型的CRUD操作 + public interface IResopwhere T:BaseEntity + { + IQueryableTable {get;} + + T GetById(object id); + void Insert(T entity); + Task InsertAsync(T entity); + void InsertBulk(IEnumerableentities); + Task InsertBulkAsync(IEnumerableentities); + void Delete(int id); + void DeleteBulk(IEnumerableids); + void Update(T entity); + void UpdateBulk(IEnumerableentities); + + + } +} + + + + + +``` +#### 新建一个IRoesops.cs +``` +用来封装CRUD方法: + + + +using Myapp.Api.Entity; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Myapp.Api.DataBase; +using Microsoft.EntityFrameworkCore; +using System; +using Myapp.Api.IResop; + +namespace Myapp.Api.IResops +{ + public class IResops :IResop where T : BaseEntity + { + private MyappDb _db; + + public IResops(MyappDb db) + { + _db = db; + } + + + + private DbSet _entity; + + protected DbSet Entity + { + get + { + if (_entity == null) + { + _entity = _db.Set(); + } + return _entity; + } + } + + public IQueryable Table + { + get + { + return Entity.AsQueryable(); + } + } + + public void Delete(int id) + { + var t = Entity.Find(id); + if (t == null) + { + throw new ArgumentNullException(nameof(t)); + } + _db.Remove(t); + _db.SaveChanges(); + } + + void IResop.DeleteBulk(IEnumerable ids) + { + var ii = new List(); + foreach (var item in ids) + { + var tmp = (int)item; + ii.Add(tmp); + } + var ts = Entity.Where(x => ii.Contains(x.Id)).ToList(); + _db.RemoveRange(ts); + _db.SaveChanges(); + } + + public T GetById(object id) + { + return Entity.Find(id); + } + + public void Insert(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayDrder = 0; + + Entity.Add(entity); + _db.SaveChanges(); + } + + public async Task InsertAsync(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayDrder = 0; + + await Entity.AddAsync(entity); + await _db.SaveChangesAsync(); + } + + public void InsertBulk(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayDrder = 0; + } + Entity.AddRange(entities); + _db.SaveChanges(); + } + + public async Task InsertBulkAsync(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayDrder = 0; + } + await Entity.AddRangeAsync(entities); + await _db.SaveChangesAsync(); + } + + public void Update(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + entity.UpdatedTime = DateTime.Now; + _db.SaveChanges(); + } + + public void UpdateBulk(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.UpdatedTime = DateTime.Now; + } + + Entity.UpdateRange(entities); + _db.SaveChanges(); + } + + + + + } +} + +``` diff --git "a/\351\231\210\346\243\256/WebApi.2021-07.01.md" "b/\351\231\210\346\243\256/WebApi.2021-07.01.md" new file mode 100644 index 0000000000000000000000000000000000000000..04388abcd3386510fc90d43fa5318c2fcce6a073 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-07.01.md" @@ -0,0 +1,314 @@ +### 创建UsersController.cs +``` +代码如下: + +using Microsoft.AspNetCore.Mvc; +using Admin3000.Backend.Api.Repository; +using Admin3000.Backend.Api.Entity; +using System.Linq; +using Admin3000.Backend.Api.Params; + +namespace Admin3000.Backend.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class UsersController : ControllerBase + { + private IRepository _usersRepository; + + public UsersController(IRepository usersRepository) + { + _usersRepository=usersRepository; + } + + [HttpGet] + public dynamic Get() + { + var users = _usersRepository.Table.ToList(); + return new + { + Code = 1000, + Data = users, + Msg = "获取用户列表成功^_^" + }; + } + + [HttpGet("{id}")] + public dynamic Get(int id) + { + var user = _usersRepository.GetById(id); + return new + { + Code = 1000, + Data = user, + Msg = "获取指定用户成功^_^" + }; + } + + + [HttpPost] + public dynamic Post(CreateUser newUser) + { + var username = newUser.Username.Trim(); + var password = newUser.Password.Trim(); + + if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) + { + return new + { + Code = 104, + Data = "", + Msg = "用户名或密码不能为空" + }; + } + + + var user = new Users + { + Username = newUser.Username, + Password = newUser.Password + }; + + _usersRepository.Insert(user); + return new + { + Code = 1000, + Data = user, + Msg = "创建用户成功^_^" + }; + } + + [HttpPut("{id}")] + public dynamic Put(int id, CreateUser updateUser) + { + var username = updateUser.Username.Trim(); + var password = updateUser.Password.Trim(); + + if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) + { + return new + { + Code = 104, + Data = "", + Msg = "用户名或密码不能为空=_=" + }; + + } + + + var user = _usersRepository.GetById(id); + + if (user == null) + { + return new + { + Code = 104, + Data = "", + Msg = "要更新的用户不存在,请确认后重试=_=" + }; + } + + user.Username = updateUser.Username; + user.Password = updateUser.Password; + + _usersRepository.Update(user); + + return new + { + Code = 1000, + Data = "", + Msg = "更新成功" + }; + } + + + [HttpDelete("{id}")] + public dynamic Delete(int id) + { + _usersRepository.Delete(id); + return new + { + Code = 1000, + Data = "", + Msg = "删除用户成功^_^" + }; + } + + } +} +``` + +### 创建Params文件夹 下CreateUser.cs +``` +代码如下: + +namespace Admin3000.Backend.Api.Params +{ + public class CreateUser + { + public string Username { get; set; } + public string Password { get; set; } + } +} +``` + +### EfRepository.cs 代码: +``` +using MyTest.Api.Entity; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MyTest.Api.Database; +using Microsoft.EntityFrameworkCore; +using System; + +namespace MyTest.Api.Repository +{ + public class EfRepository : IRepository where T : BaseEntity + { + private MyTestDb _db; + + public EfRepository(MyTestDb db) + { + _db = db; + } + + private DbSet _entity; + + protected DbSet Entity + { + get + { + if (_entity == null) + { + _entity = _db.Set(); + } + return _entity; + } + } + + public IQueryable Table + { + get + { + return Entity.AsQueryable(); + } + } + + public void Delete(object id) + { + var t = Entity.Find(id); + if (t == null) + { + throw new ArgumentNullException(nameof(t)); + } + _db.Remove(t); + _db.SaveChanges(); + } + + public void DeleteBulk(IEnumerable ids) + { + var ii = new List(); + foreach (var item in ids) + { + var tmp = (int)item; + ii.Add(tmp); + } + var ts = Entity.Where(x => ii.Contains(x.Id)).ToList(); + _db.RemoveRange(ts); + _db.SaveChanges(); + } + + public T GetById(object id) + { + return Entity.Find(id); + } + + public void Insert(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayOrder = 0; + + Entity.Add(entity); + _db.SaveChanges(); + } + + public async Task InsertAsync(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(); + } + + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayOrder = 0; + + await Entity.AddAsync(entity); + await _db.SaveChangesAsync(); + } + + public void InsertBulk(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayOrder = 0; + } + Entity.AddRange(entities); + _db.SaveChanges(); + } + + public async Task InsertBulkAsync(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.IsActived = true; + entity.IsDeleted = false; + entity.CreatedTime = DateTime.Now; + entity.UpdatedTime = DateTime.Now; + entity.DisplayOrder = 0; + } + await Entity.AddRangeAsync(entities); + await _db.SaveChangesAsync(); + } + + public void Update(T entity) + { + if (entity == null) + { + throw new ArgumentNullException(nameof(entity)); + } + + entity.UpdatedTime = DateTime.Now; + _db.SaveChanges(); + } + + public void UpdateBulk(IEnumerable entities) + { + foreach (var entity in entities) + { + entity.UpdatedTime = DateTime.Now; + } + + Entity.UpdateRange(entities); + _db.SaveChanges(); + } + } +} +``` ++ https://docs.microsoft.com/zh-cn/aspnet/core/data/ef-mvc/crud?view=aspnetcore-5.0 ++ https://www.cnblogs.com/zcqiand/p/14258059.html diff --git "a/\351\231\210\346\243\256/WebApi.2021-07.03.md" "b/\351\231\210\346\243\256/WebApi.2021-07.03.md" new file mode 100644 index 0000000000000000000000000000000000000000..fe09771303593b6813cb9253194e8d08c375c253 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-07.03.md" @@ -0,0 +1,180 @@ +#### 今天复习了C#的基础 +用XMind做了一张思维导图: +![](./imgs/1.png) + +#### 泛型 +``` +泛型就是通过参数化类型来实现在同一份代码上操作多种数据类型,利用“参数化类型”将类型抽象化,从而实现灵活的复用。 + +例子: +using System; + +namespace ConsoleApp +{ + class Program + { + class Test + { + public T obj; + public Test(T obj) + { + this.obj = obj; + } + } + static void Main(string[] args) + { + int obj1 = 2; + var test = new Test(obj1); + Console.WriteLine("int:" + test.obj); + + string obj2 = "hello world"; + var test1 = new Test(obj2); + Console.WriteLine("String:" + test1.obj); + + Console.ReadKey(); + } + } +} + + +输出: +int:2 +String:hello world + + +分析:   + +  1、 Test是一个泛型类。T是要实例化的范型类型。如果T被实例化为int型,那么成员变量obj就是int型的,如果T被实例化为string型,那么obj就是string类型的。 + +  2、 根据不同的类型,上面的程序显示出不同的值。 + + + +泛型集合: + + +namespace Web +{ + public partial class b : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + ArrayList numbers = new ArrayList(); + numbers.Add(1);//装箱 + numbers.Add(2);//装箱 + + int number = (int)numbers[1];//拆箱 + Label1.Text = number.ToString(); + } + } +} + + +``` +#### 接口 +``` +接口只包含了成员的声明,成员的定义是派生类的责任,接口本身并不实现任何功能,它只是和声明实现该接口的对象订立一个必须实现哪些行为的契约 + +定义一个接口使用 interface 关键字声明: +实例: +using System; + +//声明 +interface IMyInterface +{ + // 接口成员 + void MethodToImplement(); +} + +class InterfaceImplementer : IMyInterface +{ + static void Main() + { + InterfaceImplementer iImp = new InterfaceImplementer(); + iImp.MethodToImplement(); + } + + public void MethodToImplement() + { + Console.WriteLine("MethodToImplement() called."); + } +} + +接口的继承: +实例: +using System; + +interface IParentInterface +{ + void ParentInterfaceMethod(); +} + +interface IMyInterface : IParentInterface +{ + void MethodToImplement(); +} + +class InterfaceImplementer : IMyInterface +{ + static void Main() + { + InterfaceImplementer iImp = new InterfaceImplementer(); + iImp.MethodToImplement(); + iImp.ParentInterfaceMethod(); + } + + public void MethodToImplement() + { + Console.WriteLine("MethodToImplement() called."); + } + + public void ParentInterfaceMethod() + { + Console.WriteLine("ParentInterfaceMethod() called."); + } +} + +``` +#### 类成员 +``` +类的成员的访问级别 +public:声明为公有成员,访问不受限制。公有成员提供了类的外部界面,允许类的使用者从外部进行访问。 +protected:声明为受保护成员,只能访问包含类或从包含类派生的类。受保护成员对于外界是隐藏的。 +internal:声明为内部成员,只能访问当前程序集。 +protected internal:声明为受保护的内部成员,只能访问当前程序集或从包含类派生的类。 +private:声明为私有成员,只有该类中的成员可以访问。如果在声明中没有设置成员的访问修饰符,成员会被默认为private。 + + +例子: +public class People //类名 +{ + private static string name; //字段 + + private string sex;//字段 + + public string Sex //属性 + { + get { return sex; } + set { sex = value; } + } + + public static string Name //属性 + { + get { return People.name; } + set { People.name = value; } + } + + private People(){} //构造函数 + + public static string GetName() // 函数 + { + if (string.IsNullOrEmpty(name)) + { + name = "my name"; + } + return name; + } +} + +``` ++ 附上C#傻瓜式网址:https://www.cnblogs.com/cys168/p/8053945.html diff --git "a/\351\231\210\346\243\256/WebApi.2021-07.05.md" "b/\351\231\210\346\243\256/WebApi.2021-07.05.md" new file mode 100644 index 0000000000000000000000000000000000000000..ecaa6aaad3cc8bc9940753ddc9395c6b058a98b3 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-07.05.md" @@ -0,0 +1,33 @@ +### JWT 令牌 + +JWT结构: + +头部(Header): +>组成:令牌的类型和正在使用的签名算法 + +>签名算法常见的有 HMAC,SHA256 或 RSA;头部也用JSON描述 +例子: { + "alg": "HS256", + "typ": "JWT" + } + + + + +荷载(Payload): + +>有三种类型的claims: ++ registered claims 已注册的; ++ public claims 公开的; ++ private claims 私有的; + +签名(Signature)就是一大长串的编码 +>执行签名前准备信息: ++ 经过编码的头部 ++ 经过编码的负载 ++ 一个秘钥 ++ 在头部中指定的算法 + +附上学习网址: ++ https://www.cnblogs.com/tiger-wang/p/12892383.html ++ https://www.cnblogs.com/7tiny/archive/2019/06/13/11012035.html \ No newline at end of file diff --git "a/\351\231\210\346\243\256/WebApi.2021-07.06.md" "b/\351\231\210\346\243\256/WebApi.2021-07.06.md" new file mode 100644 index 0000000000000000000000000000000000000000..17954a00d90a57d35819c7b30b7d98f2cdc1ea20 --- /dev/null +++ "b/\351\231\210\346\243\256/WebApi.2021-07.06.md" @@ -0,0 +1,21 @@ + +``` +解决vue/cli安装慢和下载失败的问题 +安装: +npm install -g @vue/cli + +yarn global add @vue/cli //需要配置环境变量 + +转淘宝镜像提高速度: +临时使用:npm --registry https://registry.npm.taobao.org install express +永久使用:npm config set registry https://registry.npm.taobao.org + +取消镜像:npm config set registry https://registry.npmjs.org/ + + +下载cnpm:npm i -g cnpm +cnpm install -g @vue/cli + + + +``` diff --git "a/\351\231\210\346\243\256/imgs/1.png" "b/\351\231\210\346\243\256/imgs/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..718d6351e56c29f28896e0f688af2da592a78928 Binary files /dev/null and "b/\351\231\210\346\243\256/imgs/1.png" differ diff --git "a/\351\231\210\346\243\256/imgs/3.png" "b/\351\231\210\346\243\256/imgs/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..ea2da4aa161528994b553be0958668a139db3d35 Binary files /dev/null and "b/\351\231\210\346\243\256/imgs/3.png" differ