From c3ec53c8d995f7743d419403f79a04c13bd8709b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=B9=E5=AD=99=E6=9E=AB?= <3268254649@qq.com> Date: Sun, 17 Nov 2024 17:16:53 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...23\346\236\204\345\217\212\344\275\234\344\270\232.md" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "\351\241\271\345\255\231\346\236\253/20241114 \346\226\207\344\273\266\347\273\223\346\236\204\345\217\212\344\275\234\344\270\232.md" diff --git "a/\351\241\271\345\255\231\346\236\253/20241114 \346\226\207\344\273\266\347\273\223\346\236\204\345\217\212\344\275\234\344\270\232.md" "b/\351\241\271\345\255\231\346\236\253/20241114 \346\226\207\344\273\266\347\273\223\346\236\204\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000..1bd53a0 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241114 \346\226\207\344\273\266\347\273\223\346\236\204\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,8 @@ +# mvc项目.csproj -> 配置文件(定义项目的依赖项、输出项等信息) +program.cs -> 应用程序的入口 +wwwroot -> 存放静态文件(css、js、图片等文件 | 这些文件可以通过浏览器直接访问)、 +views -> 视图(需要跟控制器一一对应 | 控制器类名(去掉Controllr) =》 文件夹名称 / 控制器类名的方法名 =》 控制器类名内的方法名.cshtml文件) +controllers -> 控制器(命名需要加上Controller) + + +# \ No newline at end of file -- Gitee From fabb1f24c6ff33b099945688e0ed86b141473369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=B9=E5=AD=99=E6=9E=AB?= <3268254649@qq.com> Date: Sun, 24 Nov 2024 20:26:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...345\222\214mvc\347\273\203\344\271\240.md" | 89 +++++++++++++++ ...50\345\222\214\347\254\224\350\256\260.md" | 25 +++++ ...40\345\217\202\347\254\224\350\256\260.md" | 47 ++++++++ ...40\345\217\202\347\273\203\344\271\240.md" | 80 ++++++++++++++ ...40\345\217\202\347\254\224\350\256\260.md" | 38 +++++++ ...36\345\200\274\347\273\203\344\271\240.md" | 103 ++++++++++++++++++ 6 files changed, 382 insertions(+) create mode 100644 "\351\241\271\345\255\231\346\236\253/20241119lunnix\345\222\214mvc\347\273\203\344\271\240.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241119\346\216\247\345\210\266\345\231\250\345\222\214\347\254\224\350\256\260.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\344\274\240\345\217\202\347\254\224\350\256\260.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202\347\273\203\344\271\240.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241122\344\274\240\345\217\202\347\254\224\350\256\260.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241122\346\216\247\345\210\266\345\231\250\350\277\224\345\233\236\345\200\274\347\273\203\344\271\240.md" diff --git "a/\351\241\271\345\255\231\346\236\253/20241119lunnix\345\222\214mvc\347\273\203\344\271\240.md" "b/\351\241\271\345\255\231\346\236\253/20241119lunnix\345\222\214mvc\347\273\203\344\271\240.md" new file mode 100644 index 0000000..9745c00 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241119lunnix\345\222\214mvc\347\273\203\344\271\240.md" @@ -0,0 +1,89 @@ +# 练习 +# 效果图 + + + +# MVC练习题 +## 、创建一个控制台项目 +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 + +## 8、创建一个项目,创建一个新的控制器,名为Blogs,新的控制器拥有一个名为Index的Action,该方法返回一个视图,视图显示“神级预判” + public class BlogsController : Controller + { + public IActionResult Index() + { + return View(); + } + } +创建对应视图Views/Blogs/Index.cshtml + +

神级预判

+ 9、给第8题的新控制,添加一个新的Action,名为Music,不接受任何参数,并返回对应的视图,视图显示“顶级打野” + public IActionResult Music() + { + return View(); + } +创建对应视图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 Main { + public static void createAction(Students student) { + System.out.println("姓名: " + student.getName()); + } + + public static void main(String[] args) { + Students student = new Students("风", 20, 175); + createAction(student); + } +} \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241119\346\216\247\345\210\266\345\231\250\345\222\214\347\254\224\350\256\260.md" "b/\351\241\271\345\255\231\346\236\253/20241119\346\216\247\345\210\266\345\231\250\345\222\214\347\254\224\350\256\260.md" new file mode 100644 index 0000000..370d229 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241119\346\216\247\345\210\266\345\231\250\345\222\214\347\254\224\350\256\260.md" @@ -0,0 +1,25 @@ +## 1、登陆服务器 + - ssh root@域名 +## 2、安装nginx apt install -y ninx +## 3、测试 systemctl status nginx +## 4、安装sdk +(官网下载8.0版本) 更新软件源 apt update + +## 创建一个新的文件夹 +命令:mkdir [文件夹名] + +查看当前目录下的文件和文件夹 +命令:ls +打包程序 +dotnet publish + +## 配置 Nginx 反向代理 +server { + listen 80; + server_name 域名或者IP; + + location / { + proxy_pass http://localhost:5000; + } +} +检查是否有语法错误:nginx -t 重新加载配置:nginx -s reload \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\344\274\240\345\217\202\347\254\224\350\256\260.md" "b/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\344\274\240\345\217\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000..541a537 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\344\274\240\345\217\202\347\254\224\350\256\260.md" @@ -0,0 +1,47 @@ +通过路由传递参数: +在控制器的Action中,你可以通过在路由模板中定义参数来接收参数。 + +// GET: Home/Details/5 +public IActionResult Details(int id) +{ + var item = _context.Items.FirstOrDefault(m => m.Id == id); + return View(item); +} +通过表单传递参数: +当使用表单提交数据时,可以通过模型绑定将表单字段绑定到Action方法的参数。 + +public class Item +{ + public int Id { get; set; } + public string Name { get; set; } +} + +// POST: Home/Create +[HttpPost] +public IActionResult Create(Item item) +{ + // 保存item对象到数据库 +} +通过FromBody传递参数: +对于使用HTTP POST或PUT方法提交的JSON或XML数据,可以使用[FromBody]属性来接收数据。 + +[HttpPost] +public IActionResult Create([FromBody] Item item) +{ + // 保存item对象到数据库 +} +通过查询字符串传递参数: +当参数通过URL的查询字符串传递时,你可以在Action方法中通过参数接收它们。 + +// GET: Home/Details?name=John&age=30 +public IActionResult Details(string name, int age) +{ + // 使用name和age参数 +} +通过Header传递参数: +可以通过[FromHeader]属性来获取HTTP请求头中的参数。 + +public IActionResult GetSecretData([FromHeader] string secretKey) +{ + // 根据secretKey参数执行操作 +} \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202\347\273\203\344\271\240.md" "b/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202\347\273\203\344\271\240.md" new file mode 100644 index 0000000..a9bb4d9 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241121\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202\347\273\203\344\271\240.md" @@ -0,0 +1,80 @@ +专项练习-控制器传参 +# 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!; + } + } \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241122\344\274\240\345\217\202\347\254\224\350\256\260.md" "b/\351\241\271\345\255\231\346\236\253/20241122\344\274\240\345\217\202\347\254\224\350\256\260.md" new file mode 100644 index 0000000..13d0ca4 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241122\344\274\240\345\217\202\347\254\224\350\256\260.md" @@ -0,0 +1,38 @@ +控制器返回类型 +一般数据类型直接返回 如int、double、string、IEnumerable等数据类型 +IActionResult 一个接口,用于返回HTTP信息状态,如200、401、404等 +视图 +重定向 +ActionResult类型 将一般数据类型和HTTP状态信息混合使用 +特定于格式的操作结果:如JsonResult和ContentResult +POCO(普通旧CLR对象) +在ASP.NET Core MVC中,控制器的Action方法可以返回多种类型的值,以下是一些常见的返回类型: +IActionResult 或 ActionResult: +这是最常用的返回类型,允许你返回不同类型的HTTP响应。例如,可以返回ViewResult、RedirectResult、JsonResult等。 + +public IActionResult Index() +{ + return View(); +} +ViewResult: +返回一个视图,通常用于渲染HTML页面。 + +public IActionResult Index() +{ + return View(); +} +JsonResult: +返回一个包含JSON数据的HTTP响应。 + +public IActionResult GetJson() +{ + var data = new { Name = "张三" }; + return Json(data); +} +ContentResult: +返回一个包含纯文本内容的HTTP响应 + +public IActionResult GetText() +{ + return Content("Hello, World!", "text/plain"); +} \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241122\346\216\247\345\210\266\345\231\250\350\277\224\345\233\236\345\200\274\347\273\203\344\271\240.md" "b/\351\241\271\345\255\231\346\236\253/20241122\346\216\247\345\210\266\345\231\250\350\277\224\345\233\236\345\200\274\347\273\203\344\271\240.md" new file mode 100644 index 0000000..eaefd80 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241122\346\216\247\345\210\266\345\231\250\350\277\224\345\233\236\345\200\274\347\273\203\344\271\240.md" @@ -0,0 +1,103 @@ +渲染简单数据到页面 + public class EndController : Controller + { + [HttpGet] + public IActionResult Editone(int id) +{ + var list=new List{ + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + }, + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + }, + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + }, + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + }, + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + }, + new(){ + Title="007", + Author="张三", + Content="听 海哭的声音", + Name="Jackson" + } + }; + return View(list); +} + + } +public class SimpleViewModel +{ + public string Title { get; set; }=null!; + public string Author { get; set; }=null!; + + public string Content { get; set; }=null!; + + public string Name { get; set; }=null!; + +} + +@model List + + + + + + + + + + @foreach(var item in @Model){ + + + + + + + + } +
标题作者内容姓名操作
@item.Title@item.Author@item.Content@item.Name + + +
+ + ## 2.页面出不来 一直报错 + + ## 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
  • + } +
\ No newline at end of file -- Gitee From f48f52cac0d89b035a8378f4362c6153da1ca2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=B9=E5=AD=99=E6=9E=AB?= <3268254649@qq.com> Date: Sun, 24 Nov 2024 20:45:05 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20241119lunnix\347\273\203\344\271\240.md" | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 "\351\241\271\345\255\231\346\236\253/20241119lunnix\347\273\203\344\271\240.md" diff --git "a/\351\241\271\345\255\231\346\236\253/20241119lunnix\347\273\203\344\271\240.md" "b/\351\241\271\345\255\231\346\236\253/20241119lunnix\347\273\203\344\271\240.md" new file mode 100644 index 0000000..13a1eb3 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241119lunnix\347\273\203\344\271\240.md" @@ -0,0 +1,96 @@ +1.任务:尝试使用以下几种方式分别登录服务器,说明它们分别的注意事项,并说明它们之间的区别 + +1.ssh客户端 + +2.tabby应用 + 配置和连接 新建SSH连接 +3.xShell +点击“新建”,新建会话 +填写一个便于标识的名称 +填写服务器的公网IP +点击用户身份验证 填写服务器的用户名和密码,之后点击“确定” 填写服务器的用户名和密码,之后点击“确定” +4.putty +配置连接:用户需要输入需要连接的主机或IP地址、端口号等信息,并点击“save”按钮 选中之前保持好的配置,点击“open”打开。 + +2.任务:更新软件源,命令:apt update,并了解这一步的实际用处和意义 + + +3.任务:更新软件和补丁,命令:apt upgrade -y,并了解这一步的实际用处意义 + + + +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环境 + \ No newline at end of file -- Gitee From 459fafc0fa3bc627a8fd545a70ba4cad886bd90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=B9=E5=AD=99=E6=9E=AB?= <3268254649@qq.com> Date: Sun, 1 Dec 2024 20:40:53 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6\271\345\220\221\344\273\243\347\220\206.md" | 5 +++++ .../20241128\350\247\206\345\233\276.md" | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 "\351\241\271\345\255\231\346\236\253/20241126\346\255\243\345\217\215\346\226\271\345\220\221\344\273\243\347\220\206.md" create mode 100644 "\351\241\271\345\255\231\346\236\253/20241128\350\247\206\345\233\276.md" diff --git "a/\351\241\271\345\255\231\346\236\253/20241126\346\255\243\345\217\215\346\226\271\345\220\221\344\273\243\347\220\206.md" "b/\351\241\271\345\255\231\346\236\253/20241126\346\255\243\345\217\215\346\226\271\345\220\221\344\273\243\347\220\206.md" new file mode 100644 index 0000000..6cda697 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241126\346\255\243\345\217\215\346\226\271\345\220\221\344\273\243\347\220\206.md" @@ -0,0 +1,5 @@ +# 正向代理 +pc ————》 由于一些原因不能直接访问web服务器(例如:隐藏ip等原因) ——X——》 web服务器 pc ——通过找一个——》 代理服务器 ——让代理服务器去访问——》 web服务器 + +# 反向代理 +pc ——X——》 隐藏的web服务器 web服务器 ————》 设置一个 ————》 代理服务器 pc端 ————》 访问 ————》 代理服务器(只能通过代理服务器去访问) ————》 访问 ————》 web服务器 \ No newline at end of file diff --git "a/\351\241\271\345\255\231\346\236\253/20241128\350\247\206\345\233\276.md" "b/\351\241\271\345\255\231\346\236\253/20241128\350\247\206\345\233\276.md" new file mode 100644 index 0000000..edbd9f9 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241128\350\247\206\345\233\276.md" @@ -0,0 +1,16 @@ +# 视图定义属性 +定义: @{ 属性(键值对) } 调用: @键 + +接收view +@model 命名空间.类名 @Model.键 + +# 作业(渲染): +1. + +3. + +4. + +5. \ No newline at end of file -- Gitee From 20781a88035070fe068fb3768028f6fcb34a3f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A1=B9=E5=AD=99=E6=9E=AB?= <3268254649@qq.com> Date: Sun, 8 Dec 2024 19:57:16 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...32\345\217\212\347\254\224\350\256\260.md" | 286 ++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 "\351\241\271\345\255\231\346\236\253/20241205\344\275\234\344\270\232\345\217\212\347\254\224\350\256\260.md" diff --git "a/\351\241\271\345\255\231\346\236\253/20241205\344\275\234\344\270\232\345\217\212\347\254\224\350\256\260.md" "b/\351\241\271\345\255\231\346\236\253/20241205\344\275\234\344\270\232\345\217\212\347\254\224\350\256\260.md" new file mode 100644 index 0000000..e058793 --- /dev/null +++ "b/\351\241\271\345\255\231\346\236\253/20241205\344\275\234\344\270\232\345\217\212\347\254\224\350\256\260.md" @@ -0,0 +1,286 @@ +# 表单 +基本表单结构: + +
+ + +控制器: 在该方法名前面加 [HttpPost] 该方法参数为 (类型 变量名) + + +# 作业 + +// 1.查询特定元素 找出数组中等于5的元素。 +int [] numbers= {1,2,3,4,5,6}; + +var res1=numbers.FirstOrDefault(a=> a==5); +System.Console.WriteLine(res1); +//2.查询特定范围的元素 找出数组中在2到8之间的元素。 +var res2=numbers.Where(a=>a>=2&&a<=8); +PrintData(res2); +//3.查询并转换元素 将数组中的每个数字乘以2。 +var res3=numbers.Select(a=>a*2); +PrintData(res3); +//4.查询特定属性的对象 找出所有名字以"王"开头的学生 +List students = new List +{ + new Student {Id=1, Name = "王有才", Age = 21 }, + new Student {Id=2, Name = "王中王", Age = 22 }, + new Student {Id=3, Name = "张语嫣", Age = 23 }, + new Student {Id=4, Name = "詹宇航", Age = 35 }, + new Student {Id=5, Name = "郑雨良", Age = 26 }, +}; +var res4 = students.Where(s => s.Name.StartsWith("王")); + + foreach (var student in res4) + { + Console.WriteLine($"Id: {student.Id}, Name: {student.Name}, Age: {student.Age}"); + } +//5.查询并排序 找出所有年龄大于20岁的学生,并按年龄降序排列。 + List students_2 = new List + { + new Student {Id = 1, Name = "王有才", Age = 21 }, + new Student {Id = 2, Name = "罗婷", Age = 21 }, + new Student {Id = 3, Name = "王中王", Age = 22 }, + new Student {Id = 4, Name = "李子柒", Age = 22 }, + new Student {Id = 4, Name = "李子柒", Age = 22 }, + new Student {Id = 5, Name = "张语嫣", Age = 23 }, + new Student {Id = 6, Name = "詹宇航", Age = 35 }, + new Student {Id = 7, Name = "郑雨良", Age = 26 }, + new Student {Id = 8, Name = "欧文", Age = 26 }, + }; + + var res5 = students.Where(s => s.Age > 20).OrderByDescending(s => s.Age); + + foreach (var student in res5) + { + Console.WriteLine($"Name: {student.Name}, Age: {student.Age}"); + } + +//6.查询并去重 找出数组中所有不重复的数字。 + int[] number = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; + + var uniqueNumbers = number.Distinct(); + + foreach (var num in uniqueNumbers) + { + Console.Write(num + " "); + } + +//7.查询第一个元素 找出数组中第一个大于3的元素。 + int? res7 = number.FirstOrDefault(n => n > 3); + + if (res7.HasValue) + { + Console.WriteLine($"第一个大于3的元素是: {res7.Value}"); + } +//8.查询最后一个元素 找出数组中最后一个小于7的元素。 +int? res8 = number.LastOrDefault(n => n < 7); + + if (res8.HasValue) + { + Console.WriteLine($"最后一个小于7的元素是: {res8.Value}"); + } +//9.查询元素是否存在 检查数组中是否存在大于10的元素 +bool res9 = number.Any(n => n > 10); + + Console.WriteLine($"数组中是否存在大于10的元素: {res9}"); +//10.查询元素的计数 计算数组中大于5的元素数量。 + int count = number.Count(n => n > 5); + + Console.WriteLine($"数组中大于5的元素数量为: {count}"); +//11.查询元素的总和 计算数组中所有元素的总和。 +int sum = number.Sum(); + + Console.WriteLine($"数组中所有元素的总和为: {sum}"); +//12.查询元素的最大值 找出数组中的最大值。 +int max = number.Max(); + + Console.WriteLine($"数组中的最大值是: {max}"); +//13.查询元素的最小值 找出数组中的最小值。 +int min = number.Min(); + + Console.WriteLine($"数组中的最小值是: {min}"); + +//14.查询元素的平均值 计算数组中所有元素的平均值。 +double average = number.Average(); + + Console.WriteLine($"数组中所有元素的平均值是: {average}"); +//15.查询特定条件的元素 找出数组中能被3整除的元素。 +var res15 = numbers.Where(n => n % 3 == 0); + + foreach (var num in res15) + { + Console.Write(num + " "); + } +//16.查询并选择特定属性 找出所有学生的姓名和年龄。 +List students_3 = new List + { + new Student {Id = 1, Name = "王有才", Age = 21 }, + new Student {Id = 2, Name = "罗婷", Age = 21 }, + new Student {Id = 3, Name = "王中王", Age = 22 }, + new Student {Id = 4, Name = "李子柒", Age = 22 }, + new Student {Id = 5, Name = "张语嫣", Age = 23 }, + new Student {Id = 6, Name = "詹宇航", Age = 35 }, + new Student {Id = 7, Name = "郑雨良", Age = 26 }, + new Student {Id = 8, Name = "欧文", Age = 26 }, + }; + + var res16 = students.Select(s => new { s.Name, s.Age }); + + foreach (var item in res16) + { + Console.WriteLine($"姓名:{item.Name},年龄:{item.Age}"); + } +//17.查询并分组 按年龄分组学生,并计算每个年龄组的学生数量。 + var res17 = students_3.GroupBy(s => s.Age) + .Select(g => new + { + Age = g.Key, + Count = g.Count() + }); + + foreach (var item in res17) + { + Console.WriteLine($"年龄: {item.Age},学生数量: {item.Count}"); + } +//18.查询并联结 联结学生和课程表,找出每个学生的所有课程。 + List students_4 = new List + { + new Student {Id = 1, Name = "王有才", Age = 21 }, + new Student {Id = 2, Name = "罗婷", Age = 21 }, + new Student {Id = 3, Name = "王中王", Age = 22 }, + new Student {Id = 4, Name = "李子柒", Age = 22 }, + new Student {Id = 5, Name = "张语嫣", Age = 23 }, + new Student {Id = 6, Name = "詹宇航", Age = 35 }, + new Student {Id = 7, Name = "郑雨良", Age = 26 }, + new Student {Id = 8, Name = "欧文", Age = 26 }, + }; + + List courses = new List + { + new Course{StudentId = 1,CourseName = "英语"}, + new Course{StudentId = 1,CourseName = "数学"}, + new Course{StudentId = 2,CourseName = "语文"}, + new Course{StudentId = 3,CourseName = "物理"}, + new Course{StudentId = 4,CourseName = "化学"}, + new Course{StudentId = 4,CourseName = "生物"}, + new Course{StudentId = 4,CourseName = "语文"}, + }; + + var result = from student in students_4 + join course in courses on student.Id equals course.StudentId + group course by student.Name into studentCourses + select new + { + StudentName = studentCourses.Key, + Courses = studentCourses.Select(c => c.CourseName).ToList() + }; + + foreach (var item in result) + { + Console.WriteLine($"学生姓名: {item.StudentName}"); + Console.WriteLine("课程列表:"); + foreach (var course in item.Courses) + { + Console.WriteLine($"- {course}"); + } + Console.WriteLine(); + } +//19.查询并反转 反转数组中的元素顺序。 +int[] numbers_2 = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; + + Array.Reverse(numbers_2); + + foreach (var num in numbers_2) + { + Console.Write(num + " "); + } +//20.查询并填充 找出数组中第一个大于2的元素,并用它填充后面的所有位置。 + + + int? targetElement = numbers_2.FirstOrDefault(n => n > 2); + + if (targetElement.HasValue) + { + for (int i = 0; i < numbers.Length; i++) + { + numbers_2[i] = targetElement.Value; + } + foreach (var num in numbers_2) + { + Console.Write(num + " "); + } + } +//21.查询并排除 从数组中排除所有小于5的元素。 +var res21 = numbers_2.Where(n => n >= 5); + + foreach (var num in res21) + { + Console.Write(num + " "); + } +//22.查询并填充默认值 如果数组中存在null值,用默认值0替换 + int?[] nullableNumbers = { 1, null, 3, null, 5 }; + + var res22 = nullableNumbers.Select(n => n?? 0); + + foreach (var num in res22) + { + Console.Write(num + " "); + } +//23.查询并转换类型 将字符串数组转换为整数数组。 +string[] stringNumbers = { "1", "2", "3", "4" }; + + var intNumbers = stringNumbers.Select(s => int.Parse(s)).ToArray(); + + foreach (var num in intNumbers) + { + Console.Write(num + " "); + } +//24.查询并使用OfType过滤 从对象数组中过滤出字符串类型的元素。 + object[] objects = { "String", 123, "Another String", 456 }; + var res24 = objects.OfType().ToList(); + + foreach (var str in res24) + { + Console.WriteLine(str); + } +//25查询并使用Zip合并 合并两个数组,并创建一个包含元素对的新数组。 +int[] numbers1 = { 1, 2, 3 }; + int[] numbers2 = { 4, 5, 6 }; + + var res25 = numbers1.Zip(numbers2, (first, second) => new { First = first, Second = second }); + + foreach (var pair in res25) + { + Console.WriteLine($"({pair.First}, {pair.Second})"); + } +//26查询并使用Range生成 生成一个包含1到10的整数数组 + var evenNumbers = Enumerable.Range(1, 10).Where(n => n % 2 == 0).ToArray(); + + foreach (var num in evenNumbers) + { + Console.Write(num + " "); + } +//27查询并使用Repeat重复 重复一个元素多次,创建一个新数组。 +int[] repeatedArray = Enumerable.Repeat(5, 10).ToArray(); + + foreach (var num in repeatedArray) + { + Console.Write(num + " "); + } +//28查询并使用Take限制数量 从数组中取出前5个元素。 +int[] numbers_8 = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; + + var res28 = numbers_8.Take(5); + + foreach (var num in res28) + { + Console.Write(num + " "); + } +//29查询并使用Skip跳过元素 跳过数组中的前3个元素,然后取出剩余的元素。 + var res29 = numbers_8.Skip(3); + + foreach (var num in res29) + { + Console.Write(num + " "); + } \ No newline at end of file -- Gitee