diff --git "a/\351\273\204\351\233\252\350\212\254/20241122-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" "b/\351\273\204\351\233\252\350\212\254/20241122-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" new file mode 100644 index 0000000000000000000000000000000000000000..b05a852baa4db0918c3d6e8bea3dcc07ef24fa8a --- /dev/null +++ "b/\351\273\204\351\233\252\350\212\254/20241122-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" @@ -0,0 +1,56 @@ +## 概念: +控制器(Controller)负责接收用户的输入并调用模型(Model)和视图(View)去完成用户的需求。 + +## 请求映射 +控制器通常通过注解或配置文件与特定的URL路径关联,以处理不同的HTTP请求。 + +URL路由参数:通过`{parameter}`定义在路由模板中的参数。 +``` +public ActionResult Detail(int id) +{ + // 使用id进行数据查询和操作 +} +``` + +**具有相同参数类型包含2个方面** ++ 参数个数 ++ 参数类型 + +## 参数获取 +控制器可以通过请求对象(如HttpPost)获取请求参数、路径参数、查询参数等。 + +路由属性参数:通过特定的属性标注在参数上,用于指示如何从请求中提取参数值 +``` +public ActionResult Edit([FromBody]MyModel model) +{ + // 使用model进行操作 +} +``` + +表单数据参数:通过`HTTP POST`请求传递的表单数据。 +``` +[HttpPost] +public ActionResult Create(FormCollection form) +{ + string name = form["name"]; + // 使用name进行操作 +} +``` + +或者使用模型绑定 +``` +[HttpPost] +public ActionResult Create(MyModel model) +{ + // 使用model进行操作 +} +``` +** 其中`MyModel`是一个包含属性的类,属性名称应与表单字段的`name`属性相匹配。** + +## 参数绑定 +使用数据绑定技术,将请求参数自动映射到控制器方法的参数上。例如,在Spring MVC中,可以使用@RequestParam注解来绑定查询参数,使用@PathVariable注解来绑定路径参数。 + +# 作业 +![1](./作业/屏幕截图%202024-11-24%20220538.png) +![2](./作业/屏幕截图%202024-11-24%20220626.png) +![3](./作业/屏幕截图%202024-11-24%20220638.png) \ No newline at end of file diff --git "a/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220538.png" "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220538.png" new file mode 100644 index 0000000000000000000000000000000000000000..6f625a763db98af7750e375df42316e0e6992c3d Binary files /dev/null and "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220538.png" differ diff --git "a/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220626.png" "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220626.png" new file mode 100644 index 0000000000000000000000000000000000000000..6285e4121764d2a67f48ffdf95a5203b1f42a314 Binary files /dev/null and "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220626.png" differ diff --git "a/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220638.png" "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220638.png" new file mode 100644 index 0000000000000000000000000000000000000000..894d610fd07c0a68279999eff3a3dcba335ad407 Binary files /dev/null and "b/\351\273\204\351\233\252\350\212\254/\344\275\234\344\270\232/\345\261\217\345\271\225\346\210\252\345\233\276 2024-11-24 220638.png" differ