diff --git "a/\347\206\212\345\200\251/20241114-mvc\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241114-mvc\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..537fc9f55f8c68bb02e6eaf794c5a5f846e394d0 --- /dev/null +++ "b/\347\206\212\345\200\251/20241114-mvc\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,13 @@ +## 笔记 +1、dotnet new mvc -o 名 +cd 名 +Views->Home->项目名.cshtml +Controllers引用项目方法名 +2、wwwroot->css->建项目名.css->写样式 +3、.cshtml里用link引用样式 href="~/css/项目名.css" +4、dotnet run --project 名 +5、ctrl+c 结束任务 + +## 作业 +如图: +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411142023214.png) \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241119-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241119-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..1f206f85b33436bff736c4585d446513500a0cab --- /dev/null +++ "b/\347\206\212\345\200\251/20241119-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,16 @@ +## 笔记 + 将一个Asp.Net Core MVC部署分几步 +```` +第一步,将程序扔到服务器 + * a打包程序 dotnet publish (打包的程序位于如下文件夹:bin/Release/net8.0/publish) + * b使用一些工具将打包好的程序转到服务器,比如Scp命令 sftp工具 +第二步,安装dotnet运行时 答案是Debian这个Linux的发行版本 + 安装的方式有几种 + 包管理器 + 下载一个文件 + 将文件安装(下载一个源地址文件,安装到软件源地址) + 更新软件源 + 安装SDK + 二进制文件 + 编译安装 +```` \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241121-mvc\346\216\247\345\210\266\345\231\250.md" "b/\347\206\212\345\200\251/20241121-mvc\346\216\247\345\210\266\345\231\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..3d27580fc612250671a87fc5534d5552393e9825 --- /dev/null +++ "b/\347\206\212\345\200\251/20241121-mvc\346\216\247\345\210\266\345\231\250.md" @@ -0,0 +1,14 @@ +## 通过路由传递参数: +在控制器的Action中,你可以通过在路由模板中定义参数来接收参数。 + +## 通过表单传递参数: +当使用表单提交数据时,可以通过模型绑定将表单字段绑定到Action方法的参数。 + +## 通过FromBody传递参数: +对于使用HTTP POST或PUT方法提交的JSON或XML数据,可以使用[FromBody]属性来接收数据。 + +## 通过查询字符串传递参数: +当参数通过URL的查询字符串传递时,你可以在Action方法中通过参数接收它们。 + +## 通过Header传递参数: +可以通过[FromHeader]属性来获取HTTP请求头中的参数。 \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241122-\346\216\247\345\210\266\345\231\250.md" "b/\347\206\212\345\200\251/20241122-\346\216\247\345\210\266\345\231\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..f9ebc94f13e1549ccb9e98add74cf1dbcb525e49 --- /dev/null +++ "b/\347\206\212\345\200\251/20241122-\346\216\247\345\210\266\345\231\250.md" @@ -0,0 +1,23 @@ +控制器返回类型 一般数据类型直接返回 如int、double、string、IEnumerable等数据类型 IActionResult 一个接口,用于返回HTTP信息状态,如200、401、404等 视图 重定向 ActionResult类型 将一般数据类型和HTTP状态信息混合使用 特定于格式的操作结果:如JsonResult和ContentResult POCO(普通旧CLR对象) + + +## MVC的三大块 +controller 控制器 + +model 模型 + +view 试图 + +## 控制器返回值 +一般数据类型 + +IActionResult类型(接口) + +ActionResult类型(接口加一般数据类型) + +特定于格式的操作结果 + +Poco(普通旧CLR对象) + +## 视图 +控制器返回值通过 @model 数据类型 ----》接收数据 \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..c645867c8ea342e540e49b82d3576c89d45bcada --- /dev/null +++ "b/\347\206\212\345\200\251/20241126-1128\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,164 @@ +### 笔记 +1。正向代理和反向代理: 正向代理(Forward Proxy): 正向代理服务器位于客户端和目标服务器之间,客户端通过正向代理服务器访问目标服务器。正向代理服务器可以缓存请求、过滤内容、提供安全性等功能 区别:正向代理:客户端主动发起请求,通过正向代理服务器来访问目标服务器。正向代理服务器就像一个中间人,客户端知道正向代理的存在。 反向代理:客户端发起请求,但请求被反向代理服务器接收,然后反向代理服务器将请求转发到目标服务器。客户端并不知道目标服务器的实际地址,它们只与反向代理服务器通信。 +2。接收view @model 命名空间.类名 @Model.键名 例如: +```html +@model Blog.Controllers.Person; +

渲染(展示)对象数据到视图

+

@Model.Title

+

@Model.Author

+

@Model.Content

+

@Model.Name

+``` +3.定位点 例如: +```html + 编辑 + 删除 + 详情 +``` + +### 作业 +#### 渲染(展示)简单数据类型到视图 +```html + public IActionResult My() + { + string message = "Hello,浣熊千脆面!!"; + return View(message); + } +``` +```html +@model string + + + + + Simple Data Type Rendering + + +

@Model

+ + +``` +#### 渲染(展示)对象数据到视图 +```html +namespace Blog.Models; +public class PersonDto + { + public string Name { get; set; } = null!; + public string Age { get; set; } = null!; + public string City { get; set; } = null!; + } +``` + +```html +using Microsoft.AspNetCore.Mvc; +using Blog.Models; +namespace Blog.Controllers; +public class PersonController : Controller +{ + public ActionResult Index() + { + var person = new PersonDto + { + Name = "浣熊千脆面", + Age = "18", + City = "世 界" + }; + + return View(person); + } +} +``` + +```html +@model Blog.Models.PersonDto + + + + + Object Data Rendering + + +

名片

+

Name: @Model.Name

+

Age: @Model.Age

+

City: @Model.City

+ + +``` + +#### 渲染(展示)集合数据到视图 +```html +public class ProductsController : Controller +{ + public IActionResult List() + { + var products = new List + { + new Product { Id = 1, Name = "产品A", Price = 10.00M }, + new Product { Id = 2, Name = "产品B", Price = 15.50M }, + new Product { Id = 3, Name = "产品C", Price = 20.00M } + }; + + return View(products); + } +} +``` + +```html +@model IEnumerable + +

产品列表

+ +``` +#### 渲染(展示)包含集合数据的对象数据到视图 +```html +public class Category +{ + public int Id { get; set; } + public string Name { get; set; } + public List Products { get; set; } +} +``` + +```html +public class CategoriesController : Controller +{ + public IActionResult Index() + { + var category = new Category + { + Id = 1, + Name = "电子产品", + Products = new List + { + new Product { Id = 1, Name = "手机", Price = 300.00M }, + new Product { Id = 2, Name = "笔记本电脑", Price = 1200.00M } + } + }; + + return View(category); + } +} +``` +```html +@model Category + +

分类: @Model.Name

+
    + @foreach (var product in Model.Products) + { +
  • @product.Name: @product.Price
  • + } +
+``` +#### 尝试构建如下图所示的经典CRUD列表 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011631912.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632925.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632499.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632293.png) +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412011632051.png) diff --git "a/\347\206\212\345\200\251/20241203-\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241203-\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..8095adb703b1b7b25071e89994d6dac85fb2cc34 --- /dev/null +++ "b/\347\206\212\345\200\251/20241203-\344\275\234\344\270\232.md" @@ -0,0 +1,9 @@ + +1、从零开始,利用MVC搭建一个CRUD经典界面 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412082205358.png) + +2、完成新增(或者创建)的功能 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412082205648.png) + +3、完成修改功能 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412082206716.png) \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241205-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/\347\206\212\345\200\251/20241205-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..a73f5647e4e5a0522c19c39d8ab358a77ae50fb5 --- /dev/null +++ "b/\347\206\212\345\200\251/20241205-\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,25 @@ +### 笔记 +Linq集成查询和Lambda表达式 + +1. First() FirstOrDefault() 获取集合中(符合条件的)第一个 + + First() 这个如果没有获取到,则报错 + FirstOrDefault() 没有获取到,则返回Null + +2. Single() SingleOrDefault() 获取集合中(符合条件)的其中一个 + + Single() 这个如果没有获取到,则报错 + SingleOrDefault() 没有获取到,则返回Null + +3. Where() 获取集合中符合条件的元素,将它们筛选出来放入一个新的集合中返回 + + Where 查找符合条件的内容 + +4. Select() 返回指定内容 + + Select() 返回指定内容 Select(x=>new {x.Id}) + +### 作业 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412082206197.png) + +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202412082207854.png) \ No newline at end of file diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/17.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/17.png" new file mode 100644 index 0000000000000000000000000000000000000000..c65c085cad92e1752fa65d5f10c2067a31f575ca Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/17.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/18.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/18.png" new file mode 100644 index 0000000000000000000000000000000000000000..9960530d0531365a33e1ea8033124d835a7dec5f Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/18.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/19.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/19.png" new file mode 100644 index 0000000000000000000000000000000000000000..7beaf944a2b3f3e2372d1f4f96d27e06707f78ae Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/19.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/20.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/20.png" new file mode 100644 index 0000000000000000000000000000000000000000..e5c5d2b81b3bf3d52dc1f00e4c6c2b87642c5d12 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/20.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/21.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/21.png" new file mode 100644 index 0000000000000000000000000000000000000000..488941d436789a96da7e79245ed048e410dc3f96 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/21.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/22.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/22.png" new file mode 100644 index 0000000000000000000000000000000000000000..9a79fefb5d260eb9d8f5d54ac09d97a1524d86bc Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/22.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/23.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/23.png" new file mode 100644 index 0000000000000000000000000000000000000000..bdabb87965fa3c1ea14cfdc00662471dd60f984d Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/23.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/24.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/24.png" new file mode 100644 index 0000000000000000000000000000000000000000..a2f5bad2d8e5fd0f0a0a1f92f60e17508ebfb6d9 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/24.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/25.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/25.png" new file mode 100644 index 0000000000000000000000000000000000000000..762be3de4214b1ca4e55d107ee3aed46222dcb4a Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/25.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/26.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/26.png" new file mode 100644 index 0000000000000000000000000000000000000000..1e2db0bbb8a4765c596f81fe848be9795a6898db Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/26.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/27.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/27.png" new file mode 100644 index 0000000000000000000000000000000000000000..2ff4c9302d010995aa1d6ac50543495dbdf515cd Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/27.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/28.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/28.png" new file mode 100644 index 0000000000000000000000000000000000000000..173bfb8a2def1afb90a52f97bc1f1f9233f83d90 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/28.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/29.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/29.png" new file mode 100644 index 0000000000000000000000000000000000000000..3c682172aecdfc35da83a10e25ed6049de7626dd Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/29.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-05-13.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-05-13.png" new file mode 100644 index 0000000000000000000000000000000000000000..a92eb8e1492bfbb305cee8b74f85aaceeb8dbbbf Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-05-13.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-10-57.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-10-57.png" new file mode 100644 index 0000000000000000000000000000000000000000..e22aaeeadadf712286584b900b5b5c077f5e1ba9 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-10-57.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-21-13.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-21-13.png" new file mode 100644 index 0000000000000000000000000000000000000000..473d733db9d5eefbb7fecabbac2bf86aa77b59d7 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-21-13.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-26-31.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-26-31.png" new file mode 100644 index 0000000000000000000000000000000000000000..75a8c8dd3c54203ab86cf56f848d6f4bd432b2fd Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-26-31.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-30-40.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-30-40.png" new file mode 100644 index 0000000000000000000000000000000000000000..d38d4d82016fe7b7f36c0543cbc31db547a925d8 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-30-40.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-35-39.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-35-39.png" new file mode 100644 index 0000000000000000000000000000000000000000..71940a038dceda2af3277653600bd11ed8ad061a Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-35-39.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-40-01.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-40-01.png" new file mode 100644 index 0000000000000000000000000000000000000000..8894a86dc6e03687a7a6d38585455a4c90569425 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_15-40-01.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_16-07-18.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_16-07-18.png" new file mode 100644 index 0000000000000000000000000000000000000000..8918a85823308ff7307c3131cdbb8edf793a8f33 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/Snipaste_2024-12-08_16-07-18.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 230957.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 230957.png" new file mode 100644 index 0000000000000000000000000000000000000000..cb85b6a2ea1e0e5bb2f2c522cca96432a8f731d1 Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 230957.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231011.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231011.png" new file mode 100644 index 0000000000000000000000000000000000000000..e9a78dc9d4347ecc1babd31053993b55c5ce92bc Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231011.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231053.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231053.png" new file mode 100644 index 0000000000000000000000000000000000000000..55b9e004cc2947f496756343f4331a29dc39c31a Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231053.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231058.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231058.png" new file mode 100644 index 0000000000000000000000000000000000000000..be1e7f9ff85094f4e84eb71948690d2959dcca2c Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231058.png" differ diff --git "a/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231108.png" "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231108.png" new file mode 100644 index 0000000000000000000000000000000000000000..d84990cf7d3b3ea95c7527698d664f84a66c1b2f Binary files /dev/null and "b/\347\206\212\345\200\251/20241206Link\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-12-07 231108.png" differ diff --git "a/\347\206\212\345\200\251/\344\275\234\344\270\232/mvc\347\273\203\344\271\240.md" "b/\347\206\212\345\200\251/\344\275\234\344\270\232/mvc\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..94a8b0829e4ba6ce16346af9cc77fe94ed285d33 --- /dev/null +++ "b/\347\206\212\345\200\251/\344\275\234\344\270\232/mvc\347\273\203\344\271\240.md" @@ -0,0 +1,409 @@ +### Linux练习 +1.任务:尝试使用以下几种方式分别登录服务器,说明它们分别的注意事项,并说明它们之间的区别 + +ssh客户端 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242210253.png) +tabby应用 配置和连接 新建SSH连接 + +xShell 点击“新建”,新建会话 + +填写一个便于标识的名称 填写服务器的公网IP 点击用户身份验证 填写服务器的用户名和密码,之后点击“确定” 填写服务器的用户名和密码,之后点击“确定” putty 配置连接:用户需要输入需要连接的主机或IP地址、端口号等信息,并点击“save”按钮 选中之前保持好的配置,点击“open”打开 + +2.任务:更新软件源,命令:apt update,并了解这一步的实际用处和意义 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242211625.png) + +3.任务:更新软件和补丁,命令:apt upgrade -y,并了解这一步的实际用处意义 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242212005.png) +4.任务:熟悉并完成以下练习 + + 1.查看当前目录下的文件和文件夹----命令:ls +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121200146.png) + +2.查看当前路径----命令:pwd +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121200224.png) + +3.创建一个新的文件夹----命令:mkdir [文件夹名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121200316.png) + +4.删除一个文件夹----命令:rmdir [文件夹名](注意:只能删除空文件夹) +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201225.png) + +5.移动或重命名文件/文件夹----命令:mv [原路径] [新路径] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121200442.png) + +6.复制文件----命令:cp [源文件] [目标路径] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201103.png) + +7.删除文件----命令:rm [文件名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121200358.png) + +8.查看文件内容----命令:cat [文件名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201312.png) + +9.分页查看文件内容----命令:less [文件名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201353.png) + +10.查找文件----命令:find / -name [文件名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201504.png) + +11.查看文件权限----命令:ls -l [文件或目录名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201536.png) + +12.改变文件权限----命令:chmod [权限] [文件或目录名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201742.png) + +13.改变文件所有者----命令:chown [新所有者] [文件或目录名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201906.png) + +14.查看当前登录用户----命令:whoami +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201933.png) + +15.查看系统运行时间和平均负载----命令:uptime +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121201954.png) + +16.查看磁盘使用情况----命令:df -h +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202026.png) + +17.查看当前路径下的隐藏文件----命令:ls -a +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202055.png) + +18.创建一个空文件----命令:touch [文件名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202125.png) + +19.查看当前系统的内核版本----命令:uname -r +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202222.png) + +20.查看网络连接状态----命令:ifconfig 或 ip addr +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202250.png) + +21.安装一个软件包----命令:sudo apt-get install [软件包名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202558.png) + +22.卸载一个软件包----命令:sudo apt-get remove [软件包名] +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202623.png) + +23.更新软件包列表----命令:sudo apt-get update +![](https://gitee.com/shen-yulin20051127/imgs/raw/master/imgs/20241121202459.png) + +5.在服务器上安装SDK环境 +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242214988.png) + +### MVC练习 +1、创建一个控制台项目 dotnet new console + +2、创建一个控制项目,项目名称Blog dotnet new console -n Blog + +3、创建一个控制台项目,输出到Blog目录 dotnet new console -o Blog + +4、创建一个MVC项目,指定项目名称 dotnet new mvc -n Blog + +5、创建一个MVC项目,指定输出目录 dotnet new mvc -o BlogDir + +6、创建一个带解决方案,其下有一个MVC项目,3个类库项目的“综合项目” dotnet new sln -n Solution + +MVC项目: dotnet new mvc -n Blog + +类库: dotnet new classlib -n ClassLib1 dotnet new classlib -n ClassLib2 dotnet new classlib -n ClassLib3 + +7、创建一个项目,在默认控制器(Home)下,新增一个Action方法,名为Ok,同时为其创建对应视图以显示这个视图 创建项目 dotnet new mvc -n Blog + + ``` + public IActionResult Ok() + { + return View(); + } + ``` +创建对应视图 Views/Home/Ok.cshtml + +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242215184.png) + +8、创建一个项目,创建一个新的控制器,名为Blogs,新的控制器拥有一个名为Index的Action,该方法返回一个视图,视图显示“神级预判” + +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242215387.png) + +``` + public class BlogsController : Controller + { + public IActionResult Index() + { + return View(); + } + } + + ``` + + ![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242216870.png) + + + 创建对应视图Views/Blogs/Index.cshtml + ``` +

神级预判

+ ``` + + 9、给第8题的新控制,添加一个新的Action,名为Music,不接受任何参数,并返回对应的视图,视图显示“顶级打野” + + ``` + public IActionResult Music() + { + return View(); + } +``` + +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242218891.png) +创建对应视图Views/Blogs/Music.cshtml +``` +顶级打野 +``` +10、给第8题的新控制器,新增一个Action,名为List,不接受任何参数,并返回对应视图,视图显示一个经典CRUD界面 +``` + public IActionResult List() + { + return View(); + } +``` +创建对应视图Views/Blogs/List.cshtml + +11、新增一个控制器,名为Products,该控制器具有一个名为Edit的Action,这个Action接受一个int类型的参数id,显示这个id +``` +public class ProductsController : Controller +{ + public IActionResult Edit(int id) + { + ViewBag.Id = id; + return View(); + } +} +``` +创建对应视图Views/Products/Edit.cshtml + +``` +

Edit Product

+

编辑的产品ID:@ViewBag.Id

+ +``` +12、在11题的新控制器中,新增一个名为Create的Action,该Action接受一个类型为Students(有姓名、年龄、体长属性)的参数,并展示该参数的姓名属性 +``` +public class ProductsController : Controller{ + public IActionResult Create(){ + var pro=new ProductStudent{ + Name="宋颂", + Age="20", + Tall="186" + }; + return View(pro); +} + } + public class ProductStudent{ + public string Name{get;set;}=null!; + public string Age{get;set;}=null!; + public string Tall{get;set;}=null!; + + } +``` + +### 专项练习-控制器传参 +``` +1、简单参数传递 在一个叫Blog控制器中,定义一个叫Index的Action,并且传递一个int类型的值,id为变量名 + + +public class BlogController : Controller + { + public IActionResult Index(int id) + { + return Content(id.ToString) + } + + } + +``` +2、简单参数传递 在一个叫Blog控制器中,定义一个叫Index_2的Action,并且传递一个string类型的值,id为变量名 +``` +public class BlogController : Controller + { + + public IActionResult Index_2(string id) + { + return Content(id) + } + + } +``` +3、简单参数传递 在一个叫Blog控制器中,定义一个叫Index_3的Action,并且传递一个string类型的值,name为变量名 +``` +public class BlogController : Controller + { + public IActionResult Index_3(string name) + { + return Content(name) + } + } +``` +4、复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create的Action,并且传递一个BlogCreateDto类型的值,blogCreateDto为变量名 PS BlogCreateDto类型具有Title、Author、Content自动属性 +``` +public class BlogController : Controller + { + [HttpPost] + public IActionResult Create([FromBody] BlogCreateDto blogCreateDto){ + + return Content(blogCreateDto.Title) + } + + public class BlogCreateDto{ + + //BlogCreateDto类型具有Title、Author、Content自动属性 + public string Title{get;set;}=null!; + public string Author{get;set;}=null!; + public string Content{get;set;}=null!; + } + } +``` +5、复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_1的Action,并且传递一个Products类型的值,productCreateDto为变量名 PS Products类型具有Name、Price、Stock自动属性 +``` + +public class BlogController : Controller + { + [HttpPost] + public IActionResult Create([FromBody] Products productCreateDto){ + return Content(blogCreateDto.Title) + } + //PS Products类型具有Name、Price、Stock自动属性 + public class Products{ + public string Name{get;set;}=null!; + public string Price{get;set;}=null!; + public string Stock{get;set;}=null!; + } + } + + +``` +6、复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_2的Action,并且传递一个Students类型的值,studentCreateDto为变量名 PS Students类型具有StudentName、Sex、Age自动属性 +``` + +public class BlogController : Controller + { + public class BlogContriller : Controller{ + [HttpPost] + public IActionResult Create_2([FromBody] Students studentCreateDto){ + return Content(blogCreateDto.Title) + } + } + public class Students{ + public string Name{get;set;}=null!; + public string Price{get;set;}=null!; + public string Stock{get;set;}=null!; + } + } + + +``` +### 专项练习-基础能力 +1、生成一个随机整数,范围[0,100],注意是否包含 +``` +Random random = new Random(); +int number1 = random.Next(0, 101); +``` +2、生成一个随机整数,范围(0,100],注意是否包含 +``` +int number2 = random.Next(1, 100); +``` +3、生成10个随机整数,范围[5,80],注意是否包含 +``` +int[] numbers3 = new int[10]; +for (int i = 0; i < numbers3.Length; i++) +{ + numbers3[i] = random.Next(5, 81); +} +``` +4、定义一个字符串,字符串中有100个中文字符,需要从中随机取1个字符串 +``` +string chineseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +Random random = new Random(); +string oneChineseCharacter = chineseCharacters[random.Next(chineseCharacters.Length)]; +``` +5、定义一个字符串,字符串中有100个中文字符,需要从中随机取5-50个字符,组成新的字符 +``` +int length = random.Next(5, 51); +StringBuilder sb = new StringBuilder(); +for (int i = 0; i < length; i++) +{ + sb.Append(chineseCharacters[random.Next(chineseCharacters.Length)]); +} +string fiveToFiftyChineseCharacters = sb.ToString(); +``` +6、定义2个字符串,第一个字符串中放百家姓,第二个字符串中放中文字符,要求从第一个字符串随机取得一个姓,再从第二个字符串中随机获得1到2个字符组成新字符串,和第一个字符串取得的姓组成一个姓名 +``` +string surnames = "刘赵钱孙李周吴郑王冯陈卫蒋沈韩杨"; +string givenNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +int surnameIndex = random.Next(surnames.Length); +string surname = surnames[surnameIndex].ToString(); +int givenNameLength = random.Next(1, 3); +StringBuilder givenNameSb = new StringBuilder(); +for (int i = 0; i < givenNameLength; i++) +{ + givenNameSb.Append(givenNames[random.Next(givenNames.Length)]); +} +string givenName = givenNameSb.ToString(); +string name = surname + givenName; +``` +7、利用以上方法,随机生成100个BlogCreateDto类型(有Title、Author、Content属性)的对象,其中的内容都是随机生成且长度不定,并将其渲染到视图 +``` +public class BlogCreateDto +{ + public string Title { get; set; } + public string Author { get; set; } + public string Content { get; set; } +} + +List blogs = new List(); +for (int i = 0; i < 100; i++) +{ + BlogCreateDto blog = new BlogCreateDto + { + Title = GenerateRandomString(10, 50), // 随机标题长度10-50 + Author = name, // 使用上面生成的姓名 + Content = GenerateRandomString(100, 1000) // 随机内容长度100-1000 + }; + blogs.Add(blog); +} + +string GenerateRandomString(int minLength, int maxLength) +{ + StringBuilder contentSb = new StringBuilder(); + int contentLength = random.Next(minLength, maxLength + 1); + for (int i = 0; i < contentLength; i++) + { + contentSb.Append(chineseCharacters[random.Next(chineseCharacters.Length)]); + } + return contentSb.ToString(); +} +``` + +### 专项练习-控制器返回值 +1. +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242229835.png) +2. +![](https://gitee.com/xiong-qian_-a/picture-bed/raw/master/images/202411242230050.png) + +3.渲染集合数据到页面 +``` +public IActionResult CollectionView() +{ + CollectionViewModel model = new CollectionViewModel + { + Items = new List { "Item1", "Item2", "Item3" } + }; + return View(model); +} +``` +``` +@model YourNamespace.CollectionViewModel + +
    + @foreach (var item in Model.Items) + { +
  • @item
  • + } +
+ +Gitee - 基于 Git 的代码托管和研发协作平台 +``` \ No newline at end of file