From 4ff2a203ac19961ba570b8c9a90039c799048f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=A2=A7=E4=BB=99?= Date: Sun, 24 Nov 2024 00:00:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...347\275\262mvc\351\241\271\347\233\256.md" | 61 ++++++ ...50\347\275\262\350\241\245\345\205\205.md" | 23 +++ .../2024-11-22\344\274\240\345\217\202.md" | 177 ++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 "\351\203\221\347\242\247\344\273\231/2024-11-18Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" create mode 100644 "\351\203\221\347\242\247\344\273\231/2024-11-20Debian\351\203\250\347\275\262\350\241\245\345\205\205.md" create mode 100644 "\351\203\221\347\242\247\344\273\231/2024-11-22\344\274\240\345\217\202.md" diff --git "a/\351\203\221\347\242\247\344\273\231/2024-11-18Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" "b/\351\203\221\347\242\247\344\273\231/2024-11-18Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" new file mode 100644 index 0000000..36c1120 --- /dev/null +++ "b/\351\203\221\347\242\247\344\273\231/2024-11-18Linux\351\203\250\347\275\262mvc\351\241\271\347\233\256.md" @@ -0,0 +1,61 @@ +## mvc项目 + 1. 先在网站解析域名(已备完案的) + 2. 在页面按window键加r键打开 + 3. 输入cmd打开命令提示符 + 4. 先测试解析的域名是否生效 + 5. 登陆服务器 + - ssh root@域名 + 6. 安装nginx apt install -y ninx + 7. 测试 systemctl status nginx + 8. 安装sdk + 1. 官网下载8.0版本 + 2. 找到Linux,安装包管理器 + 3. 找到dabian,,在终端运行一下命令 + -wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + -dpkg -i packages-microsoft-prod.deb + -rm packages-microsoft-prod.deb(可有可无) + - 更新软件源 apt update + - apt-get install -y dotnet-sdk-8.0(安装) + 4. 测试是否成功 dotnet + 9. 在/var/下创建www文件夹,并在www文件夹下创建以域名为名称的文件夹 + - mkdir /var/www + - cd /var/www + - mkdir 文件名(以域名) + - cd 文件名 + 10. ls -al 查看文件夹下的目录 + 11. 在终端下创建mvc项目 + - dotnet new mvc -n 项目名称 + 12. 切换到指定目录 + 13. 在该目录中添写程序 + 13. 打包写好程序 + - dotnet publish + 14. 切换到打包好的目录下 + - cd .\bin\Release\net8.0\publis + 15. 找到后缀为.dll 运行 + 16. 使用ls查看打包的内容 + 17. 上传打包好的文件到服务器 + - scp -r * root@域名(主机):/var/www/文件名 + 18. 查看上传的文件 ls -al + 19. 运行服务器 + + dotnet xx.dll + 20. 在浏览器上打开显示被拒绝了 + 21. 另开一个窗口 + - 运行curl http://localhost:5000 (切记服务器要运行) + 22. 使用反向代理 + + - 配置文件 + cd /etc/nginx/conf.d/ + - vim 域名.conf + 23. 按i键进入编辑模式 + server{ + listen 80; //端口 + server_name 域名; + location / { + proxy_pass http://localhost:5000; + } + } + 24. 检查语法 + - nginx -t + 25. 重新加载配置文件 + - nginx -s reload \ No newline at end of file diff --git "a/\351\203\221\347\242\247\344\273\231/2024-11-20Debian\351\203\250\347\275\262\350\241\245\345\205\205.md" "b/\351\203\221\347\242\247\344\273\231/2024-11-20Debian\351\203\250\347\275\262\350\241\245\345\205\205.md" new file mode 100644 index 0000000..3a334fc --- /dev/null +++ "b/\351\203\221\347\242\247\344\273\231/2024-11-20Debian\351\203\250\347\275\262\350\241\245\345\205\205.md" @@ -0,0 +1,23 @@ +## Debian部署Mvc的先决条件 +1. 在服务器上安装运行环境或调试环境(必要条件) + - 如何安装sdk包管理器 + - 在官网下载文件 + wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + - 注册文件 + - 删除软件源apt update + - 安装sdk apt-get install-sdk-8.0 + - 在Linux上安装软件或应用常用方式如下: + - 包管理器 + - 使用二进制文件安装 + - 编译安装 +2. 将打包好的程序上传到指定目录 + - scp -r ./* root@域名(主机):/var/www/文件名 + - xftp +3.一般建议使用nginx做反向代理 + server{ + listen 80; //端口 + server_name 域名; + location / { + proxy_pass http://localhost:5000; + } + } diff --git "a/\351\203\221\347\242\247\344\273\231/2024-11-22\344\274\240\345\217\202.md" "b/\351\203\221\347\242\247\344\273\231/2024-11-22\344\274\240\345\217\202.md" new file mode 100644 index 0000000..b77ea00 --- /dev/null +++ "b/\351\203\221\347\242\247\344\273\231/2024-11-22\344\274\240\345\217\202.md" @@ -0,0 +1,177 @@ +[静态1](http://zhengmuyun.cn/静态1.png) +[静态2](http://zhengmuyun.cn/静态2.png) +[静态3](http://zhengmuyun.cn/静态3.png) +[静态4](http://zhengmuyun.cn/静态4.png) +[静态5](http://zhengmuyun.cn/静态5.png) +[静态6](http://zhengmuyun.cn/静态6.png) +[静态7](http://zhengmuyun.cn/静态7.png) +[静态8](http://zhengmuyun.cn/静态8.png) +[静态9](http://zhengmuyun.cn/静态9.png) +[静态10](http://zhengmuyun.cn/静态10.png) +重要代码 + +``` +---mvc练习 +2.dotnet new console -n Blog +3. mkdir Blog +cd Blog +dotnet net console +4.Dotnet new mvc -n Blog +5. mkdir Bb +cd Bb +dotnet new mvc + +6.Dotnet new sln -n Gg +Dotnet new mvc -n Xx +Dotnet sln add Xx + dotnet new classlib -n C1 + dotnet new classlib -n C2 + dotnet new classlib -n C3 +dotnet sln add C1 +dotnet sln add C2 +dotnet sln add C3 + cd Xx + dotnet add reference ../C1/C1.csproj + dotnet add reference ../C2/C2.csproj + dotnet add reference ../C3/C3.csproj + cd .. +dotnet build + cd Xx + dotnet run + +public IActionResult Edit(int id){ + return Content(id.ToString()); + } + public IActionResult Index(){ + var students=new Students{ + Name="零零", + Age="33", + Weight="55", + Height="34" + }; + return View(students); + } + // [HttpPost] + // public IActionResult Create([FromBody]Students students){ + // // return Content(JsonSerializer.Serialize(students)); + // return View(students); + // } + + +public class Students{ + public string Name{get;set;}=null!; + public string Age{get;set;}=null!; + public string Weight{get;set;}=null!; + public string Height{get;set;}=null!; +} +---------控制器传参 +public class BlogController:Controller{ + public IActionResult Index(int id){ + // return Content(id.ToString()); + var blogCreateDto=new BlogCreateDto{ + Title="点击", + Author="可可", + Content="阿斯蒂芬巴萨的语法可是对于" + }; + var productCreateDto=new Products{ + Name="可可", + Price="33", + Stock="22d" + }; + // return View(blogCreateDto); + return View(productCreateDto); + } + public IActionResult Ss(){ + var studentCreateDto=new Students{ + StudentName="可可", + Sex="男", + Age="21" + }; + return View(studentCreateDto); + } + public IActionResult Index_2(string id){ + return Content(id.ToString()); + } + public IActionResult Index_3(string name){ + return Content(name.ToString()); + } + [HttpPost] + public IActionResult Create([FromBody] BlogCreateDto blogCreateDto){ + // return Content(JsonSerializer.Serialize(blogCreateDto)); + return View(blogCreateDto); + } + [HttpPost] + public IActionResult Create_1([FromBody] Products productCreateDto){ + // return Content(JsonSerializer.Serialize(productCreateDto)); + return View(productCreateDto); + } + [HttpPost] + public IActionResult Create_2([FromBody]Students studentCreateDto){ + return Content(JsonSerializer.Serialize(studentCreateDto)); + } +} +2.任务:更新软件源,命令:apt update,并了解这一步的实际用处和意义 + - 获取最新的软件包信息 + - 支持系统稳定性 + - 提高软件包管理效率 + - 修复安全漏洞 + - 准备软件包升级 +3.更新软件和补丁,命令:apt upgrade -y,并了解这一步的实际用处意义 +1. 安装可用更新 +2.自动解决依赖关系 +3.提高系统安全性 +4.保持系统稳定 +5.自动化和一致性 +6.维护软件的兼容性 +7.获取新功能和改进 + + +``` +## 传参 + +1. 简单传参(单个) + + public IActionResult Edit(int id){ + return Content(id.ToString()); + } + + - 如有多个简单传参形式则需修改Program.cs中的pattern里的值 + 例如: pattern: "{controller=Home}/{action=Index}/{age?}"; + public IActionResult Edit(int age){ + return Content(age.ToString()); + } + +2. 复杂传参 + + - 第一步 + [HttpPost] + public IActionResult Create([FromBody]Students students){ + return Content(JsonSerializer.Serialize(students)); + } + + - 该方式需创建视图中创建一个与控制器相对应对视图文件(书写样式时可用),但还是在postman软件中查看(前提要运行该程序F5) + + +- 第二步需创建一个类这个类里有属性 +public class Students{ + public string Name{get;set;}=null!; + public string Age{get;set;}=null!; + public string Weight{get;set;}=null!; + public string Height{get;set;}=null!; +} +- 第三部,因该方法在浏览器中无法查看,需到Postman这个软件中查看结果 + +3. 因第二个方法无法在浏览器中查看,则需在控制器中方法(公共)中构造一个新的对象,将要显示的信息放在其中(可在页面显示),在将信息传给视图 + public IActionResult Index(){ + var students=new Students{ + Name="零零", + Age="33", + Weight="55", + Height="34" + }; + return View(students); + } -- Gitee