diff --git "a/\345\224\220\345\256\207\345\247\227/20241118-mvc\346\216\247\345\210\266\345\231\250.md" "b/\345\224\220\345\256\207\345\247\227/20241118-mvc\346\216\247\345\210\266\345\231\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..3e571146fe6b9a2ab83d198b8a1bd1138c374ecb --- /dev/null +++ "b/\345\224\220\345\256\207\345\247\227/20241118-mvc\346\216\247\345\210\266\345\231\250.md" @@ -0,0 +1,40 @@ +# 控制器 +**控制器 (本质其实就是一个类型,通过继承Controller这个类型来获得所有关于控制器的功能)** +- 模型绑定-如何给方法传递参数 +- Restful + - get + - get /blogs + - 获取很多博客文章列表 + - get /blogs/18 + - 获取指定id为18的博客文章 + - post post/blogs + - 新增一篇博客文章,内容在body + - put put /blogs/1 + - 修改id为1的博客,内容在body + - delete delete /blogs/2 + - 删除id为2的博客 + + + - get + - get /products + - 获取商品列表 + - get /products/18 + - 获取指定id为18的商品信息 + - post post/products + - 新增一个商品,内容在body + - put put /products/1 + - 修改id为1的商品,内容在body + - delete delete /products/2 + - 删除id为2的商品 + + + + - get + - get /books/13/comments + - 获取id为13的那本书的评论列表 + - post post/books/13/comments + - 给id为13的那本书新增一条评论 + - put put /books/13/comments/99 + - 修改id为13的那本书的评论 + - delete delete /books/13/comments/39 + - 删除id为13的那本书下,id为39的评论 diff --git "a/\345\224\220\345\256\207\345\247\227/20241120-mvc\345\246\202\344\275\225\344\270\212\344\274\240\345\217\202\346\225\260.md" "b/\345\224\220\345\256\207\345\247\227/20241120-mvc\345\246\202\344\275\225\344\270\212\344\274\240\345\217\202\346\225\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..bdd2cf9f350cbf7c3d157efbb45e87d7cfd977e4 --- /dev/null +++ "b/\345\224\220\345\256\207\345\247\227/20241120-mvc\345\246\202\344\275\225\344\270\212\344\274\240\345\217\202\346\225\260.md" @@ -0,0 +1,52 @@ + +1. 新建一个控制器--`LarsController.cs` + ``` + using Microsoft.AspNetCore.Mvc; + namespace Blog.Controller; + public class LarsController:Controller -----继承 + { + public IActionResult Index() + { + return View(); + } + } + ``` +2. 获取id + ``` + // program.cs中默认值是id + + public IActionResult Index(int id) + { + return Content(id.ToString()); + } + ``` +3. 获取方法中的name + ``` + public class Students + { + public string name{get;set;}=null!; ----字符串需要=null! + public int age{get;set;} + } + + // 在LarsController中 + [HttpPost] + public IActionResult Create([FromBody]Students stu) + { + return Content(stu.name); + } + + //[FromBody]传递复杂数据 + +作业 + +![1](./img/1.png) +![2](./img/2.png) +![3](./img/3.png) +![4](./img/4.png) +![5](./img/5.png) +![6](./img/6.png) +![7](./img/7.png) +![8](./img/8.png) +![9](./img/9.png) +![10](./img/10.png) +![11](./img/11.png) \ No newline at end of file diff --git "a/\345\224\220\345\256\207\345\247\227/img/1.png" "b/\345\224\220\345\256\207\345\247\227/img/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..0317fbbf28b58ec69a0d9dabf07bb88a6988a925 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/1.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/10.png" "b/\345\224\220\345\256\207\345\247\227/img/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..4936797543ad63c92bb0033958f262b7ad3e8a37 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/10.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/11.png" "b/\345\224\220\345\256\207\345\247\227/img/11.png" new file mode 100644 index 0000000000000000000000000000000000000000..333f63fd403488476f1fd31904c3703b8b0d2592 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/11.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/2.png" "b/\345\224\220\345\256\207\345\247\227/img/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..01c836d37b46c33bac0805b4abd8ceedb501ea0e Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/2.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/3.png" "b/\345\224\220\345\256\207\345\247\227/img/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..fd7b8962832dadc3247d705353c6217dcdaaef33 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/3.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/4.png" "b/\345\224\220\345\256\207\345\247\227/img/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..982f346bb89976d7e1bbb809db0f3c1edad9bbbd Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/4.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/5.1.png" "b/\345\224\220\345\256\207\345\247\227/img/5.1.png" new file mode 100644 index 0000000000000000000000000000000000000000..c99c28dd7d575a78e03f11ef2c005fc44a84cd7e Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/5.1.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/5.png" "b/\345\224\220\345\256\207\345\247\227/img/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..0c2fb2742ce175481b6acc6eaf67b4a86a5ea4db Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/5.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/6.png" "b/\345\224\220\345\256\207\345\247\227/img/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..230cc999121e462d81d3deda934b7db32b8643f2 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/6.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/7.1.png" "b/\345\224\220\345\256\207\345\247\227/img/7.1.png" new file mode 100644 index 0000000000000000000000000000000000000000..702cf23abd23b732b8f1a1ddb14df07894490877 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/7.1.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/7.png" "b/\345\224\220\345\256\207\345\247\227/img/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..95156df3c66aec723fda917c50d67ac75a16f068 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/7.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/8.png" "b/\345\224\220\345\256\207\345\247\227/img/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..c6b5c87360960a87f06e2ed8680bb7796b9f90b7 Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/8.png" differ diff --git "a/\345\224\220\345\256\207\345\247\227/img/9.png" "b/\345\224\220\345\256\207\345\247\227/img/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..a6ee959f4b0f4db982a017199183eadbbfa0610c Binary files /dev/null and "b/\345\224\220\345\256\207\345\247\227/img/9.png" differ