diff --git "a/\346\235\216\345\205\264\351\234\262/20241118--MVC\351\203\250\347\275\262\351\241\271\347\233\256.md" "b/\346\235\216\345\205\264\351\234\262/20241118--MVC\351\203\250\347\275\262\351\241\271\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..15f35aefca635bd89dded0da01a5b163e18475a2 --- /dev/null +++ "b/\346\235\216\345\205\264\351\234\262/20241118--MVC\351\203\250\347\275\262\351\241\271\347\233\256.md" @@ -0,0 +1,26 @@ +# 在MVC中部署项目 +`mkdir`:在同一级创建一个新的目录 + +`dotnet new MVC -o .\Blog\...\`:创建项目 + +`dotnet sln .\Blog\ add .\Blog\`:将文件拖到解决方案(常) + +`program.cs`:项目入口 + +`.csproj`:.csproj文件的主要作用是为开发工具提供信息 + +`{}app.json`:配置文件 + +`wwwroot`:静态资源 + +`using Microsoft.AspNetCore.MVC;`:引用命名空间 + +**在引用命名空间,如果不是SDK自带的包的话,需先安装依赖包。** + +方法三要素:方法名称,参数,返回值 + +`dotnet watch`:热重载(hot reload) + +`` + +`` \ No newline at end of file diff --git "a/\346\235\216\345\205\264\351\234\262/20241120--MVC\351\203\250\347\275\262\345\210\260\346\234\215\345\212\241\345\231\250.md" "b/\346\235\216\345\205\264\351\234\262/20241120--MVC\351\203\250\347\275\262\345\210\260\346\234\215\345\212\241\345\231\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..8f0d55d70e92fc292258ad91d6283c9bababcb7b --- /dev/null +++ "b/\346\235\216\345\205\264\351\234\262/20241120--MVC\351\203\250\347\275\262\345\210\260\346\234\215\345\212\241\345\231\250.md" @@ -0,0 +1,49 @@ +# Debian部署MVC(ASP.Net.Core)的先决条件。 +## 一、在服务器上安装了运行环境或者是调用环境(重要条件) +1、 如何安装SDK包管理器 ++ 先下载个文件 ++ 在注册文件 `wget curl` ++ 删除那已经注册过的文件 `rm` ++ 更新软件源 `apt update` ++ 安装SDK `SDK apt install dontnet-SDK-8.0 -y` + +2、在Linux上安装软件或者应用常用方式如下 ++ 包管理器 (相对于用户来说最简单) ++ 使用二进制文件安装 (相对于用户来说次简单) ++ 编译安装 (相对于用户来说最难) + +## 二、将打包好的程序上传到指定目录(重要条件) +1、scp工具 `scp -r(上传包含文件夹)` ./* root@xxxx.xxx(;) :/var/www/xxxx.xx(域名) ++ 打包 `dotnet publish` ++ 测试(工作中一般建议测试可以视情况省略) ++ 上传 + +2、xftp + +## 三、一般建议使用index做反向代理(ps:如果不做反向代理,则这个可不用) +``` +server { + listen 80; + server-name 解析.域名 + + location { + proxy-pass 服务器地址 + } +} +``` + +测试:`nginx -t` + + +`cd /var/www` + +检测是否安装SDK: `dotnet` + +打包(准备发布):`dotnet publish` + +解析:云解析——>解析设置 + +查看:`ping` + + + \ No newline at end of file diff --git "a/\346\235\216\345\205\264\351\234\262/20241122--\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" "b/\346\235\216\345\205\264\351\234\262/20241122--\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" new file mode 100644 index 0000000000000000000000000000000000000000..460b2ef4b0cfe1622b42d3425cf30089ad797edf --- /dev/null +++ "b/\346\235\216\345\205\264\351\234\262/20241122--\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" @@ -0,0 +1,64 @@ +## 概念: +控制器(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](./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/\346\235\216\345\205\264\351\234\262/img/1.png" "b/\346\235\216\345\205\264\351\234\262/img/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..0317fbbf28b58ec69a0d9dabf07bb88a6988a925 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/1.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/10.png" "b/\346\235\216\345\205\264\351\234\262/img/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..4936797543ad63c92bb0033958f262b7ad3e8a37 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/10.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/11.png" "b/\346\235\216\345\205\264\351\234\262/img/11.png" new file mode 100644 index 0000000000000000000000000000000000000000..333f63fd403488476f1fd31904c3703b8b0d2592 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/11.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/2.png" "b/\346\235\216\345\205\264\351\234\262/img/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..01c836d37b46c33bac0805b4abd8ceedb501ea0e Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/2.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/3.png" "b/\346\235\216\345\205\264\351\234\262/img/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..fd7b8962832dadc3247d705353c6217dcdaaef33 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/3.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/4.png" "b/\346\235\216\345\205\264\351\234\262/img/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..982f346bb89976d7e1bbb809db0f3c1edad9bbbd Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/4.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/5.1.png" "b/\346\235\216\345\205\264\351\234\262/img/5.1.png" new file mode 100644 index 0000000000000000000000000000000000000000..c99c28dd7d575a78e03f11ef2c005fc44a84cd7e Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/5.1.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/5.png" "b/\346\235\216\345\205\264\351\234\262/img/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..0c2fb2742ce175481b6acc6eaf67b4a86a5ea4db Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/5.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/6.png" "b/\346\235\216\345\205\264\351\234\262/img/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..230cc999121e462d81d3deda934b7db32b8643f2 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/6.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/7.1.png" "b/\346\235\216\345\205\264\351\234\262/img/7.1.png" new file mode 100644 index 0000000000000000000000000000000000000000..702cf23abd23b732b8f1a1ddb14df07894490877 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/7.1.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/7.png" "b/\346\235\216\345\205\264\351\234\262/img/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..95156df3c66aec723fda917c50d67ac75a16f068 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/7.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/8.png" "b/\346\235\216\345\205\264\351\234\262/img/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..c6b5c87360960a87f06e2ed8680bb7796b9f90b7 Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/8.png" differ diff --git "a/\346\235\216\345\205\264\351\234\262/img/9.png" "b/\346\235\216\345\205\264\351\234\262/img/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..a6ee959f4b0f4db982a017199183eadbbfa0610c Binary files /dev/null and "b/\346\235\216\345\205\264\351\234\262/img/9.png" differ