学习目标:熟练掌握简单的.net core api
学习内容:
- 知道 ASP.NET Core Web API 的创建
- 掌握 ASP.NET Core Web API 基本用法
- 掌握 增删改查
- 实现单个简易项目
学习时间:
- 周一至周五上午9.30-下午4.30
- 周六晚上 9 点-晚上 11 点
- 共30天左右
学习产出:
例如:
- 项目一个
- CSDN 技术博客 1 篇
开始创建项目
打开 Visual Studio 2022 (没有该版本打开自己版本就行)创建新项目
找到ASP.NET Core Web API模块进行创建(没有在搜索模块自行搜索)
设置自己的名字并选择自己需要保存的地址
取消配置https,进行创建
实现项目的增删改查
在项目中添加文件夹
并添加依赖包
(右键项目名找到就可以打开添加依赖包)
在Model中开始创建类
Beauty:
using SqlSugar;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautyManagement.Model
{
public class Beauty
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
// 图片
public string Pic { get; set; } = "";
// 创建者
public string UserName { get; set; } = "";
// 描述
public string Description { get; set; } = "";
// 美容套餐外键
//[ForeignKey("BeatyPackageId")]
public int BeautyPackageId { get; set; } = 0;
}
}
BeautyPackage:
using SqlSugar;
namespace BeautyManagement.Model
{
public class BeautyPackage
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
// 创建者
public string UserName { get; set; } = "";
// 描述
public string Description { get; set; } = "";
// 如果使用代码初始化数据库需要注释下面一行代码
public List<Beauty> Beautys { get; set; }
}
}
Role:
using SqlSugar;
namespace BeautyManagement.Model
{
public class Role
{
[SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
User:
using SqlSugar;
namespace BeautyManagement.Model
{
public class User
{
[SugarColumn(IsPrimaryKey=true,IsIdentity =true)] // 设置id为主键,并自动递增
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
// 头像
public string Picture { get; set; } = "";
public int RoleId { get; set; }
// public Role Role { get; set; } // 导航属性
}
}
在