diff --git "a/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linq\351\233\206\346\210\220\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" "b/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linq\351\233\206\346\210\220\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" new file mode 100644 index 0000000000000000000000000000000000000000..2077a565df88daa8cd9a0fb33b0d8d2e26d4f29e --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linq\351\233\206\346\210\220\346\237\245\350\257\242\345\222\214Lambda\350\241\250\350\276\276\345\274\217.md" @@ -0,0 +1,263 @@ +``` + // public IActionResult Gin() + // { + // int[] numbers = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; +// int[] reversedNumbers = numbers.Reverse().ToArray(); + +// // 输出反转后的数组 +// foreach(var Num in reversedNumbers){ +// Console.WriteLine(string.Join(", ", reversedNumbers)); +// } + + // int fillValue = numbers.First(n => n > 2); + + // 创建一个新数组,用fillValue填充后面的位置 + // int[] filledNumbers = new int[numbers.Length]; + // Array.Copy(numbers, filledNumbers, numbers.Length); // 首先复制原数组 + // for (int i = Array.IndexOf(numbers, fillValue); i < filledNumbers.Length; i++) + // { + // filledNumbers[i] = fillValue; // 从第一个大于2的元素的索引开始替换 + // } + + // 注意:这里我们其实没有用Lambda表达式来直接填充数组, + // 因为LINQ主要用于查询,而不是修改数据。但是,我们使用了LINQ的First方法来找到填充值。 + + // 输出填充后的数组 +// foreach(var num in filledNumbers){ +// Console.WriteLine(string.Join(", ", filledNumbers)); +// } +// int[] filteredNumbers = numbers.Where(n => n >= 5).ToArray(); + + // 输出过滤后的数组 + // int?[] nullableNumbers = { 1, null, 3, null, 5 }; + + // 使用Select方法将null替换为0 +// int[] filledNumbers = nullableNumbers.Select(n => n ?? 0).ToArray(); +// foreach (var num in filledNumbers){ +// Console.WriteLine(string.Join(", ", filledNumbers)); +// } + + +// foreach(var num in filteredNumbers){ +// Console.WriteLine(string.Join(", ", filteredNumbers)); +// } +// string[] stringNumbers = { "1", "2", "3", "4" }; + + // 使用Select方法和int.Parse将字符串转换为整数 + // int[] intNumbers = stringNumbers.Select(int.Parse).ToArray(); +// foreach(var num in intNumbers){ +// Console.WriteLine(string.Join(", ", intNumbers)); +// } +// object[] objects = { "String", 123, "Another String", 456 }; + +// // 使用OfType方法过滤出字符串类型的元素 +// List stringList = objects.OfType().ToList(); +// foreach(var num in stringList){ +// Console.WriteLine(string.Join(", ", stringList)); +// } + +// return View(); +// } +// } + // int[] numbers = { 1, 2, 3, 4, 5, 6 }; + // var result = numbers.Where(number => number ==5); + // foreach (var num in result) + // { + // Console.WriteLine(num); + // } + // return View(result); + // int[] numbers = { 1, 2, 3, 4, 5, 6 }; + // var result =numbers.Where(number => number >=2 && number <=8); + // foreach (var num in result) + // { + // Console.WriteLine(num); + // } + // return View(result); + // int[] numbers = { 1, 2, 3, 4, 5, 6 }; + // var doubledNumbers = numbers.Select(number => number * 2); + + // // 同样,doubledNumbers 是一个 IEnumerable,如果需要数组,可以调用 ToArray() 方法 + // int[] doubledNumbersArray = doubledNumbers.ToArray(); + + // foreach (var num in doubledNumbersArray) + // { + // Console.WriteLine(num); + // } + // return View(doubledNumbersArray); + + // 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 olderStudents = students.Where(student => student.Age < 23); + // foreach (var student in olderStudents) + // { + // Console.WriteLine($"Name: {student.Name}, Age: {student.Age}"); + // } +// List students = 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 age = students.OrderByDescending(student => student.Age >20); +// foreach (var student in age) +// { +// Console.WriteLine($"Id: {student.Id}, Name: {student.Name}, Age: {student.Age}"); +// } + +// int[] numbers = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; + +// // 查询并去重,找出数组中所有不重复的数字 +// var Numbers = numbers.Distinct(); + +// // 打印结果 +// Console.WriteLine("Unique numbers:"); +// foreach (var number in Numbers) +// { +// Console.WriteLine(number); +// } + +// var num= new List{1, 2, 3, 4, 5, 6,18,23,64,7,18,2,3 }; +// int n = num.First(number => number > 3); +// foreach (var number in num) +// { +// // 输出结果 +// Console.WriteLine("数组中第一个大于3的元素是: " + n); +// } + +// return View(); + +// int[] numbers = { 1, 2, 3, 4, 5, 6, 18, 23, 64, 7, 18, 2, 3 }; + + // 使用Lambda表达式和LINQ的Last方法,查找数组中最后一个小于7的元素 + // int lastNumberLessThanSeven = numbers.Last(number => number < 7); + + // + // foreach (var number in numbers) + // {Console.WriteLine("数组中最后一个小于7的元素是: " + lastNumberLessThanSeven);} + + +// bool hasNumberGreaterThanTen = numbers.Any(number => number > 10); + +// // 输出结果 +// foreach (var number in numbers) +// { +// Console.WriteLine("数组中是否存在大于10的元素: " + hasNumberGreaterThanTen); +// } + +// int countOfNumbersGreaterThanFive = numbers.Count(number => number > 5); + + // 输出结果 + // Console.WriteLine("数组中大于5的元素数量是: " + countOfNumbersGreaterThanFive); + // int sumOfAllNumbers = numbers.Sum(); + // int maxValue = numbers.Min(); + // double averageValue = numbers.Average(); + // var divisibleByThree = numbers.Where(number => number % 3 == 0); + + // 输出结果 + // foreach (var number in numbers) + // { + // Console.WriteLine("数组中能被3整除的元素是: " + string.Join(", ", divisibleByThree)); + // } +// List students = 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 studentNamesAndAges = students.Select(student => new + // { + // student.Name, + // student.Age + // }); + + // foreach (var item in studentNamesAndAges) + // { + // Console.WriteLine($"Name: {item.Name}, Age: {item.Age}"); + // } + // var ageGroups = students.GroupBy(student => student.Age) + // .Select(group => new + // { + // Age = group.Key, + // Count = group.Count() + // }); + + // foreach (var ageGroup in ageGroups) + // { + // Console.WriteLine($"Age: {ageGroup.Age}, Count: {ageGroup.Count}"); + // } +// List students = 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 studentCourses = from student in students +// join course in courses on student.Id equals course.StudentId +// select new +// { +// StudentName = student.Name, +// CourseName = course.CourseName +// }; + +// foreach (var sc in studentCourses) +// { +// Console.WriteLine($"Student: {sc.StudentName}, Course: {sc.CourseName}"); +// } + +// // 如果你想要按学生分组并列出他们的所有课程 +// var studentCourseGroups = from student in students +// join course in courses on student.Id equals course.StudentId +// group course by student into g +// select new +// { +// StudentName = g.Key.Name, +// Courses = string.Join(", ", g.Select(c => c.CourseName)) +// }; + +// foreach (var group in studentCourseGroups) +// { +// Console.WriteLine($"Student: {group.StudentName}, Courses: {group.Courses}"); +// } +// return View(); + +// internal class Course +// { +// internal int StudentId; + +// public string CourseName { get; internal set; } +// } +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linux\347\273\203\344\271\240.md" "b/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linux\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..1b02f9029c2aaf15e2cf9a9bac90ea72119c0bf7 --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\344\273\243\347\240\201/Linux\347\273\203\344\271\240.md" @@ -0,0 +1,306 @@ +### 任务4: +``` +1.查看当前目录下的文件和文件夹 + 命令:ls + 2.查看当前路径 + 命令:pwd + 3.创建一个新的文件夹 + 命令:mkdir 文件夹名 + mkdir 作业代码.html + 4.删除一个文件夹 + 命令:rmdir 文件夹名(注意:只能删除空文件夹) + 5.移动或重命名文件/文件夹 + 命令:mv 文件名称 目标未知文件名称 + mv Beast.html 代码 + 6.复制文件 + 命令:cp 源文件 目标路径 + cp Beast.html 许海怡 ——(许海怡文件夹被复制到代码文件夹中) + 7.删除文件 + 命令:rm 文件名 + rm 许海怡 + 8.查看文件内容 + 命令:cat [文件名] + cat Linux练习.md ——(一堆奇奇怪怪的文字) + 9.分页查看文件内容 + 命令:less [文件名] + less Index.cshtml + 10.查找文件 + 命令:find / -name [文件名] + find /许海怡/代码 -name "Beast.html"——(无效开关) + 11.查看文件权限 + 命令:ls -l [文件或目录名] + ls -l 代码 + 12.改变文件权限 + 命令:chmod [权限] [文件或目录名] + chmod user,u 代码————/usr/bin/chmod: invalid mode: ‘user,u’ +Try '/usr/bin/chmod --help' for more information. + 13.改变文件所有者 + 命令:chown [新所有者] [文件或目录名] + chown all 代码 ————/usr/bin/chown: invalid user: ‘all’ + 14.查看当前登录用户 + 命令:whoami + whoami————laptop-nh8nqpnq\34752 + 15.查看系统运行时间和平均负载 + 命令:uptime + 会出现像这样的12:34:56 up 2 day, 3:45, 2 users, load average: 0.00, 0.01, 0.05 + 16.查看磁盘使用情况 + 命令:df -h + 会出现Filesystem Size Used Avail Use% Mounted on +D:/Git 821G 25G 796G 3% / +C: 120G 120G 299M 100% /c +E: 58G 2.3G 56G 4% /e + 17.查看当前路径下的隐藏文件 + 命令:ls -a + 18.创建一个空文件 + 命令:touch [文件名] + touch dirt。html + 19.查看当前系统的内核版本 + 命令:uname -r + 3.4.10-bc1f6498.x86_64 + 20.查看网络连接状态 + 命令:ifconfig 或 ip addr + 21.安装一个软件包 + 命令:sudo apt-get install [软件包名] + sudo apt-get install htop + 22.卸载一个软件包 + 命令:sudo apt-get remove [软件包名] + sudo apt-get remove htop + 23.更新软件包列表 + 命令:sudo apt-get update + sudo apt-get update htop +``` +### MVC练习 +``` +创建一个控制台项目,没有任何选项,体会项目名称和什么有关系 +dotnet new console + +创建一个控制项目,项目名称Blog + public IActionResult Hello() + { + return View(); + } +创建一个控制台项目,输出到Blog目录 +dotnet new console -o Bolgs +创建一个MVC项目,指定项目名称 +dotnet new sln -o FaceBook +创建一个MVC项目,指定输出目录 +dotnet new sln -n FaceBook +创建一个带解决方案,其下有一个MVC项目,3个类库项目的“综合项目” +dotnet new sln -o FaceBook +dotnet new mvc -o src/Face.Web +dotnet new classlib -o src/Face.Core(类库项目) +dotnet new classlib -o src/Face.Domain(类库项目) +dotnet new classlib -o src/Face.Application(类库项目) +【创建的解决方案与项目啥的都没关系】 +想要解决方案管理它旗下的项目——dotnet sln add .\src\Face.Domain\ +dotnet sln add .\src\Blog.Face.Domain\ +dotnet sln add .\src\Blog.Face.Application\ +创建一个项目,在默认控制器(Home)下,新增一个Action方法,名为Ok,同时为其创建对应视图以显示这个视图 +先在Views Home里手动创建一个Ok.cshtml文件 +再在HomeController中 +public IActionResult Ok(){ + return View(); + } +创建一个项目,创建一个新的控制器,名为Blogs,新的控制器拥有一个名为Index的Action,该方法返回一个视图,视图显示“神级预判” +在作业截图里面练习7 +给第8题的新控制,添加一个新的Action,名为Music,不接受任何参数,并返回对应的视图,视图显示“顶级打野” +在作业截图里面 +给第8题的新控制器,新增一个Action,名为List,不接受任何参数,并返回对应视图,视图显示一个经典CRUD界面 +截图里 +新增一个控制器,名为Products,该控制器具有一个名为Edit的Action,这个Action接受一个int类型的参数id,显示这个id +截图id +先在Views 创建一个Products 再在这里手动创建一个Edit.cshtml文件 +再在HomeController中 + public IActionResult Edit(int id) + { + ViewBag.Id = id; + return View(); + } +在11题的新控制器中,新增一个名为Create的Action,该Action接受一个类型为Students(有姓名、年龄、体长属性)的参数,并展示该参数的姓名属性 +public class Students + { + public required string Name { get; set; } + public int Age { get; set; } + public double Height { get; set; } + } + + +``` + +### 专项练习-控制器传参 +``` +简单参数传递 在一个叫Blog控制器中,定义一个叫Index的Action,并且传递一个int类型的值,id为变量名 +public class Index{ +public int Id { get; set; } +} +简单参数传递 在一个叫Blog控制器中,定义一个叫Index_2的Action,并且传递一个string类型的值,id为变量名 + public string Index_2(int id) + { + return id.ToString(); + } +简单参数传递 在一个叫Blog控制器中,定义一个叫Index_3的Action,并且传递一个string类型的值,name为变量名 +public class Index_3{ +public string Name { get; set; } +} +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create的Action,并且传递一个BlogCreateDto类型的值,blogCreateDto为变量名 + public class Create{ +public string Title{get;set;}=null!; +public string Author{get;set;}=null!; +public string Content{get;set;}=null!; +} + +PS BlogCreateDto类型具有Title、Author、Content自动属性 + +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_1的Action,并且传递一个Products类型的值,productCreateDto为变量名 + public class Create_1{ +public string Title{get;set;}=null!; +public string Author{get;set;}=null!; +public string Content{get;set;}=null!; +} + +PS Products类型具有Name、Price、Stock自动属性 + +复杂参数传递 在一个叫Blog的控制器中,定义一个名为Create_2的Action,并且传递一个Students类型的值,studentCreateDto为变量名 +public class blogCreateDto_2{ +public string Title{get;set;}=null; +public string Author{get;set;}=null; +public string Content{get;set;}=null; +} +PS Students类型具有StudentName、Sex、Age自动属性 + + +``` +### 专项练习-基础能力 +``` +生成一个随机整数,范围[0,100],注意是否包含 + public int Beast (int min, int max) + { + Random random = new Random(); + int number = random.next(0,101); + } +生成一个随机整数,范围(0,100],注意是否包含 +int number2 = random.Next(1, 100); +生成10个随机整数,范围[5,80],注意是否包含 +int[] numbers3 = new int[10]; +for (int i = 0; i < numbers3.Length; i++) +{ + numbers3[i] = random.Next(5, 81); +} +定义一个字符串,字符串中有100个中文字符,需要从中随机取1个字符串 +string chineseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +Random random = new Random(); +string oneChineseCharacter = chineseCharacters[random.Next(chineseCharacters.Length)]; +定义一个字符串,字符串中有100个中文字符,需要从中随机取5-50个字符,组成新的字符 +int length = random.Next(5, 51); +StringBuilder sb = new StringBuilder(); +for (int i = 0; i < length; i++) +{ + sb.Append(chineseCharacters[random.Next(chineseCharacters.Length)]); +} +string fiveToFiftyChineseCharacters = sb.ToString(); +定义2个字符串,第一个字符串中放百家姓,第二个字符串中放中文字符,要求从第一个字符串随机取得一个姓,再从第二个字符串中随机获得1到2个字符组成新字符串,和第一个字符串取得的姓组成一个姓名 +string surnames = "啊诶与诶哦股鹅肉诶二米课次都进入哦了诶而已瑟吉欧"; +string givenNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +int surnameIndex = random.Next(surnames.Length); +string surname = surnames[surnameIndex].ToString(); +int givenNameLength = random.Next(1, 3); +StringBuilder givenNameSb = new StringBuilder(); +for (int i = 0; i < givenNameLength; i++) +{ + givenNameSb.Append(givenNames[random.Next(givenNames.Length)]); +} +string givenName = givenNameSb.ToString(); +string name = surname + givenName; +利用以上方法,随机生成100个BlogCreateDto类型(有Title、Author、Content属性)的对象,其中的内容都是随机生成且长度不定,并将其渲染到视图 + +```public class EndController : Controller + { + [HttpGet] + public IActionResult Editone(int id) +{ + var list=new List{ + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }, + + new(){ + Title="你今天开心吗", + Author="佚名", + Content="你觉得呢", + }; + return View(list); + } +} + } +### 专项练习-控制器返回值 +``` +渲染简单数据到页面 +public IActionResult CollectionView() +{ + CollectionViewModel model = new CollectionViewModel + { + Items = new List { "Item1", "Item2", "Item3" } + }; + return View(model); +} +渲染复杂数据到页面 +public IActionResult CollectionView() +{ + CollectionViewModel model = new CollectionViewModel + { + Items = new List { "Item1", "Item2", "Item3" } + }; + return View(model); +} +渲染集合数据到页面 +public IActionResult CollectionView() +{ + CollectionViewModel model = new CollectionViewModel + { + Items = new List { "Item1", "Item2", "Item3" } + }; + return View(model); +} +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/1.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..756dbc732d3f6373178d1211eba3ae99bbdd421a Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/1.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/10.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/10.png" new file mode 100644 index 0000000000000000000000000000000000000000..6868aa56e8b7e805517538b590d89b1f5bb4cd61 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/10.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/11.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/11.png" new file mode 100644 index 0000000000000000000000000000000000000000..63b74a460db8b7988e7bb29b08925146a5293c84 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/11.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/12.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/12.png" new file mode 100644 index 0000000000000000000000000000000000000000..f96a255c85c6a346100ced02cff7ba322a69dbde Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/12.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/13.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/13.png" new file mode 100644 index 0000000000000000000000000000000000000000..f909c6f2157c5ebaacfc7b1478d9ca89094988cb Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/13.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/14.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/14.png" new file mode 100644 index 0000000000000000000000000000000000000000..2d142daa4f944c45e9631fc12b10522ae97e8574 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/14.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/15.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/15.png" new file mode 100644 index 0000000000000000000000000000000000000000..73eb8a9ce76eb822380a20e78d29130122a1e4bf Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/15.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/2.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..4c3b5a753e2bde355d4c04c7cd47833d2def2c60 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/2.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/3.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..08eaf7fa9922d4b767c6dd025fd2b8d0a72ed0f3 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/3.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/4.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..cdceac1cc32c6e6fda0e3dd884130f5490f9c1c0 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/4.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/5.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..1deabf7dcdbd071dfce39412fc658978e80f8329 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/5.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/6.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..c25d9bc71bdb7550751c774f978639d06e6cac56 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/6.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/7.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/7.png" new file mode 100644 index 0000000000000000000000000000000000000000..45d72fd6a7be8ee520b5082a40adabee69a82349 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/7.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/8.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/8.png" new file mode 100644 index 0000000000000000000000000000000000000000..87788fbc7867db1f2b177cba83edb278c01b1dc1 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/8.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/9.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/9.png" new file mode 100644 index 0000000000000000000000000000000000000000..b6a18d08f71ae803d677ab762279ddb17ac3accb Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/9.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/CRUD\347\273\217\345\205\270\347\225\214\351\235\2421.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/CRUD\347\273\217\345\205\270\347\225\214\351\235\2421.png" new file mode 100644 index 0000000000000000000000000000000000000000..b64ead101f7f0119864d6837578c8ecf9ce92571 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/CRUD\347\273\217\345\205\270\347\225\214\351\235\2421.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/OK+\345\215\207\347\272\247\351\242\204\345\210\244.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/OK+\345\215\207\347\272\247\351\242\204\345\210\244.png" new file mode 100644 index 0000000000000000000000000000000000000000..46bb7590ddaaa6d2c6ea3376011c215a11840ad3 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/OK+\345\215\207\347\272\247\351\242\204\345\210\244.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/id\346\216\245\346\224\266.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/id\346\216\245\346\224\266.png" new file mode 100644 index 0000000000000000000000000000000000000000..6930ef6a2fffa44b12bd22c79933d55b2c9b2351 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/id\346\216\245\346\224\266.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_2.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_2.png" new file mode 100644 index 0000000000000000000000000000000000000000..80bd3bb5f0cf4f5b31cd09685ca503856e2317f2 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_2.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_3.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_3.png" new file mode 100644 index 0000000000000000000000000000000000000000..9c40fea9d5fed3d0c429fca3723f00a745e9d7f6 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/index_3.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/list.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/list.png" new file mode 100644 index 0000000000000000000000000000000000000000..ae044d76eab1c1d557e36f7843a487c9bc6e948d Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/list.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/ssh.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/ssh.png" new file mode 100644 index 0000000000000000000000000000000000000000..8ba6b8f3de2b4ace6031ff25bcefb764dcb67207 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/ssh.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/string name.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/string name.png" new file mode 100644 index 0000000000000000000000000000000000000000..72729952aa74ac91f4e94c5192fecf786cc0a84c Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/string name.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/student.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/student.png" new file mode 100644 index 0000000000000000000000000000000000000000..56fa54c9b46930e72051dbdb2a85ebe78cca2e5e Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/student.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\344\277\256\346\224\271.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\344\277\256\346\224\271.png" new file mode 100644 index 0000000000000000000000000000000000000000..5cdac8f2fc0331935bb4b69d398ef7a79ed8e1c7 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\344\277\256\346\224\271.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\226\260\345\242\236.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\226\260\345\242\236.png" new file mode 100644 index 0000000000000000000000000000000000000000..278fa2d33e5da7c4562b66631a82a0e4316a3c24 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\226\260\345\242\236.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223.jpg" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223.jpg" new file mode 100644 index 0000000000000000000000000000000000000000..195ebf18492d28df3038da01fa92e24433d8afce Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223.jpg" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2232.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2232.png" new file mode 100644 index 0000000000000000000000000000000000000000..7242ac563d4cb2cd1298398409cfa082a64ff617 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2232.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2234.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2234.png" new file mode 100644 index 0000000000000000000000000000000000000000..536b9ae355a4143014071b289290984f03d90371 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2234.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2235.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2235.png" new file mode 100644 index 0000000000000000000000000000000000000000..bcff558e5baef8c8c6867bbd994ac1e1d653ee84 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\2235.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223\344\270\200.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223\344\270\200.png" new file mode 100644 index 0000000000000000000000000000000000000000..7ffea45e6f934a0871e71c39d1a19c51d65d6984 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\346\270\262\346\237\223\344\270\200.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\350\241\250\346\240\274\346\210\252\345\233\276.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\350\241\250\346\240\274\346\210\252\345\233\276.png" new file mode 100644 index 0000000000000000000000000000000000000000..e468a9bef01540b58d28dc3d4d3f27cab1fca9ed Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\350\241\250\346\240\274\346\210\252\345\233\276.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\351\241\266\347\272\247\346\211\223\351\207\216.png" "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\351\241\266\347\272\247\346\211\223\351\207\216.png" new file mode 100644 index 0000000000000000000000000000000000000000..29070989acdc960fefd7ec212442b2a7f6684510 Binary files /dev/null and "b/\350\256\270\346\265\267\346\200\241/\344\275\234\344\270\232\346\210\252\345\233\276/\351\241\266\347\272\247\346\211\223\351\207\216.png" differ diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241114-\345\210\233\345\273\272MVC\351\241\271\347\233\256.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241114-\345\210\233\345\273\272MVC\351\241\271\347\233\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..f076c429364556008214b437173043d97c2da217 --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241114-\345\210\233\345\273\272MVC\351\241\271\347\233\256.md" @@ -0,0 +1,45 @@ +``` +基本结构为—— + @startmindmap + *解决方案 + *项目 + *后台管理项目 + *前后端分离技术 + *前端 + *vue3 + *后端 + *Admin3000.Core + *Admin3000.Domain + *Admin3000.EntityFrameworkCore + *Admin3000.Infrastructure + *1.项目组织结构 + * 解决方案和项目结构 + * mvc项目的结构 + *2.Linux的一些技巧 + @endmindmap + + 提示:Asp.Net Core 平台下 全部适用帕斯卡命名方式(所有的单词首字母大写) + +``` +``` +创建一个MVC项目 :在终端命令栏里输入——dotnet new mvc //创建一个新的ASP.NET.MVC项目 + 方法一:dotnet new mvc -o Blog 创建一个名为Blog 的项目 +方法二:dotnet new classlib (类库)-o Blog.Core //创建一个模板类库用于多个项目用 + +dotnet new sln //已成功创建模板“解决方案文件”。 +cd .\项目名\ //进入项目目录 +dotnet run //运行项目 +创建一个带解决方案,其下有一个MVC项目,3个类库项目的“综合项目” +dotnet new sln -o FaceBook +dotnet new mvc -o src/Face.Web +dotnet new classlib -o src/Face.Core(类库项目) +dotnet new classlib -o src/Face.Domain(类库项目) +dotnet new classlib -o src/Face.Application(类库项目) +【创建的解决方案与项目啥的都没关系】 +想要解决方案管理它旗下的项目——dotnet sln add .\src\Face.Domain\ +dotnet sln add .\src\Blog.Face.Domain\ +dotnet sln add .\src\Blog.Face.Application\ +访问网址链接出现制作的网站 + +``` + diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241115-\346\211\223\345\214\205\344\270\212\344\274\240.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241115-\346\211\223\345\214\205\344\270\212\344\274\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..4b774ea4685778ac1bb90875a414abcc476a287c --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241115-\346\211\223\345\214\205\344\270\212\344\274\240.md" @@ -0,0 +1,30 @@ +``` +在项目名下创建一个文件————mkdir .\项目名\需创建的文件名 +在文件下创建一个项目————dotnet new mvc -o .\项目名\文件名\项目名.文件之下的项目名(在windows和linux中用/来做分隔符) +dotnet sln add .\项目名\add .\项目名\文件名\ + +home下文件的名称来源于控制项目中方法的名称 + +创建后缀为.cs项目时 +第一步引入命名空间(引入命名空间之前,需要引用对应包或者库 + +using Microsoft.AspNetCore.Mvc; + + namespace Practice.Controllers; + + public class ProductsController : Controller +{} + +ProductsController与Controllers下文件的名称是有一定关系的一般情况下这两是一致的 +``` +``` +如何改端口号:在properties的jiso后缀文件中找到——profiles{applicationUrl} +ctrl +r可以结束 +端口一般在0-65535,系统保留端口0-1000 +``` +``` +打包 dotnet publish +拷贝 scp.路径在172.16.90.250和ikuai中例如(.\bin\Release\net8.0\publish\*root@域名:/var/www/域名路径) + +安装SDK +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241119-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241119-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" new file mode 100644 index 0000000000000000000000000000000000000000..0d0fb6c2d18645670d8126e693f948fd9cfb399a --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241119-\346\216\247\345\210\266\345\231\250\344\274\240\345\217\202.md" @@ -0,0 +1,25 @@ +``` +将一个ASP.Net Core MVC 部署分几步 +1.将程序扔到服务器 +a打包程序 +b使用一些工具将打包好的程序传到服务器 +2.安装dotnet运行时 +在Debian这个Linux发行版本安装sdk或者运行时 +安装方式有——1包管理器:下载一个文件,将文件安装,更新软件源,安装sdk +2二进制文件 +3编译安装 +``` +``` +action本质上其实是一个方法,方法的签名、三要素——函数名、参数、返回值。 +简单参数传递 在一个叫Blog控制器中,定义一个叫Index的Action,并且传递一个int类型的值,id为变量名 +public class Index{ +public int Id { get; set; } +} + +传递到my workspace上 +public IActionResult Edit([FromBody]变量名 obj){ + return Content (obj.Nickname) +} + + +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241120-\345\220\257\345\212\250\351\205\215\347\275\256.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241120-\345\220\257\345\212\250\351\205\215\347\275\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..e715d8e9e1898927bbb099a792e74f6481dddf2e --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241120-\345\220\257\345\212\250\351\205\215\347\275\256.md" @@ -0,0 +1,23 @@ +``` +当用户访问 `http://localhost:5000/Home/Index/5` 时: +1. **控制器**: 匹配到 `HomeController`。 +2. **操作方法**: 匹配到 `Index` 方法。 +3. **参数**: 路由参数 `id` 的值为 `5`,并传递到 `Index` 方法中。 + +在路由模式中,`{id?}` 定义了一个可选参数,其名称为 `id`。控制器方法的参数名必须与此占位符一致,例如: +如果路由模式为 `{productId?}`,则方法参数名应为 `productId`。 + + 参数名不匹配时,将导致请求无法正确解析参数。 + 在路由模式中, `{id?}` 表示一个可选的URL参数,占位符名称为 `id`。在控制器方法中,参数名称也必须与占位符名称匹配,即 `id`。如果路由模式中使用了其他参数名,例如 `{productId?}`,那么控制器方法中的参数名也应相应更改为 `productId`。 + 路由模式 `"{controller=Home}/{action=Index}/{id?}"` : + 允许通过 URL 直接访问控制器和方法。 +参数名需要与占位符一致,避免请求解析问题。 +在路由模式中,`{id?}` 定义了一个可选参数,其名称为 `id`。控制器方法的参数名必须与此占位符一致,例如: +如果路由模式为 `{productId?}`,则方法参数名应为 `productId`。 + +参数名不匹配时,将导致请求无法正确解析参数。 + +``` +``` + +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241121-\350\277\224\345\233\236\345\200\274.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241121-\350\277\224\345\233\236\345\200\274.md" new file mode 100644 index 0000000000000000000000000000000000000000..ad191c3e6ed3d9e39fd59d13a82f372b2dfd79bd --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241121-\350\277\224\345\233\236\345\200\274.md" @@ -0,0 +1,25 @@ +``` +IActionResult 类型(接口) +IActionResult是一个接口,定义了生成HTTP响应所需的方法。ASP.NET Core MVC提供了多种实现IActionResult的类,如ViewResult(返回视图)、ContentResult(返回文本内容)、JsonResult(返回JSON数据)等。 + +控制器中的操作方法可以通过返回这些类型的实例来生成不同的HTTP响应。例如: + +csharp +public IActionResult Index() +{ + // 返回视图 + return View(); +} + +public IActionResult GetData() +{ + // 返回JSON数据 + return Json(new { Name = "John Doe", Age = 30 }); +} +``` +``` + ActionResult类型(接口加一般数据类型) +虽然IActionResult本身是一个接口,不直接包含数据,但ASP.NET Core MVC中的许多IActionResult实现都允许您指定要返回的数据。例如,ContentResult允许您指定文本内容,而JsonResult允许您指定要序列化为JSON的对象。 + +此外,您还可以创建自定义的IActionResult实现,以返回特定类型的数据。例如,您可以创建一个返回CSV文件的自定义结果类型。 +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241126-\346\255\243\345\220\221\344\273\243\347\220\206\345\217\215\345\220\221\344\273\243\347\220\206.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241126-\346\255\243\345\220\221\344\273\243\347\220\206\345\217\215\345\220\221\344\273\243\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..0c407d706132d10c5740c74af2b7c07a84abbbc2 --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241126-\346\255\243\345\220\221\344\273\243\347\220\206\345\217\215\345\220\221\344\273\243\347\220\206.md" @@ -0,0 +1,17 @@ +``` +正向代理概念 +正向代理是一种位于客户端和服务器之间的代理服务器。客户端将请求发送给正向代理,然后由代理服务器将请求转发给目标服务器。服务器将响应返回给代理服务器,再由代理服务器将响应转发给客户端。正向代理对客户端是透明的,客户端无需知道实际服务器的地址。 + +2.2 正向代理特点 +1. 隐藏客户端身份: 正向代理可以隐藏客户端的真实IP地址,保护客户端的隐私。 +2. 访问控制: 正向代理可以根据一定的规则限制或允许客户端的访问请求,实现访问控制功能。 +3. 缓存加速: 正向代理可以缓存经常访问的页面或资源,提高访问速度,减轻服务器负担。 +``` +``` +反向代理概念 +反向代理是一种位于服务器和客户端之间的代理服务器。客户端将请求发送给反向代理,然后由代理服务器根据一定的规则将请求转发给后端服务器。后端服务器将响应返回给代理服务器,再由代理服务器将响应转发给客户端。反向代理对客户端是透明的,客户端无需知道实际服务器的地址,只需将反向代理当作目标服务器一样发送请求就可以了。 + +3.2 反向代理特点 +1. 负载均衡: 反向代理可以根据后端服务器的负载情况,将请求分发到不同的服务器上,实现负载均衡,提高系统的整体性能。 +2. 安全性增强: 反向代理可以隐藏后端服务器的真实地址和端口,防止直接攻击(如DoS/DDoS)。同时,还可以实现SSL加密、访问控制等安全功能。 +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241203-\350\241\250\345\215\225.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241203-\350\241\250\345\215\225.md" new file mode 100644 index 0000000000000000000000000000000000000000..46e785ce7d016ff26fbe8fe67a2391c1c1f55a48 --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241203-\350\241\250\345\215\225.md" @@ -0,0 +1,54 @@ +``` +静态构造函数,只会在程序启动的时候运行一次,仅运行1次,以后不再运行 +public static class Db +{ +public static List Blogs {get;set;} +static Db() +{ + Blogs = []; + for(var i =1;i<=10;i++){ + var tmp =new Blogs + { + + }; + Blogs.Add(tmp); + } +} +} +``` +``` +// using Microsoft.Extensions.ObjectPool; + +// namespace Blog.Models; +// 静态类型,用于模拟数据 +//静态构造函数,只会在程序启动的时候运行一次,仅运行1次,以后不再运行 +// public static class Db +// { +// public static List Blogs {get;set;} +// static Db() +// { +// Blogs = []; +// for(var i =1;i<=10;i++){ +// var tmp =new Blogs +// { +// Id=i, +// Title="粉雾海" +// Content="窗外的云由浅色转为深红" +// Author="易烊千玺" +// }; +// Blogs.Add(tmp); +// } +// } +// } +``` +``` +// namespace Blog.Models; +//此为博客模型,后续根据这个生成数据库表 +// public class Blogs +// { +// public int Id{get;set} +// public string Title{get;set}=null!; +// public string Content{get;set}=null!; +// public string Author{get;set}=null!; +// } +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241206-\346\226\260\345\242\236\345\210\240\351\231\244.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241206-\346\226\260\345\242\236\345\210\240\351\231\244.md" new file mode 100644 index 0000000000000000000000000000000000000000..d4f47ad3d2e046488be828d11fdc4ddfd6c364f3 --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241206-\346\226\260\345\242\236\345\210\240\351\231\244.md" @@ -0,0 +1,55 @@ +## Linq集成查询(关联Lambda) +1. First FirstOrDefault 找到第一个符合条件的元素 + - First(x=>Id==id) 返回第一个Id等于id的元素,如果都没有返回符合的则报错 + - FirstOrDefault(x=>Id==id) 返回第一个Id等于id的元素,如果都没有返回符合的则返回null +2. Single SingleOrDefault + - Single() 返回第一个元素,如果没有报错 + - SingleOrDefault() 返回第一个元素,如果没有,返回null +3. where(x=>x.score>=80 && x.sex=1) 查找所有成绩大于等于80并且性别为1的所有元素 +4. Select(x=>new {x.Id,x.Score}) 以新的{x.Id,x.Score}对象的形式,返回新的集合 +## 增加 +1. 增加页面--Create.cshtml + ``` + @model Blog.Models.Blogs; +
+
+
+
+ +
+ ``` +2. 创建-保存表单结果的action + ``` + [HttpPost] + public Blogs Create(Blogs input) + { + //返回输入的值 + return input; + } + ``` + ## 编辑 +1. 编辑页面--Edit.cshtml + ``` + Index.cshtml页面中编辑按钮 + 编辑 + + @model Blog.Models.Blogs; +
+
+
+
+
+ +
+ ``` + +2. 编辑-保存表单结果的action + ``` + //获取内容 + public IActionResult Edit(int id) + { + var blog=Db.Blogs.FirstOrDefault(x=>x.Id==id); + return View(blog); + } + +``` \ No newline at end of file diff --git "a/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241210-12-13-ling\346\237\245\350\257\242\350\256\262\350\247\243\357\274\214\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223.md" "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241210-12-13-ling\346\237\245\350\257\242\350\256\262\350\247\243\357\274\214\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..0b109d39138c340eaf6d3f7c0fd5441c2531219a --- /dev/null +++ "b/\350\256\270\346\265\267\346\200\241/\350\257\276\345\240\202\347\254\224\350\256\260/20241210-12-13-ling\346\237\245\350\257\242\350\256\262\350\247\243\357\274\214\350\277\236\346\216\245\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,78 @@ +检索元素的子集以生成新序列,而不修改各个元素。 然后,查询可能以各种方式对返回的序列进行排序或分组,如下面的示例所示(假定 scores 是 int[]): +``` +IEnumerable highScoresQuery = + from score in scores + where score > 80 + orderby score descending + select score; +``` +下面的代码示例演示一个简单查询表达式,它具有一个数据源、一个筛选子句、一个排序子句并且不转换源元素。 该查询以 select 子句结尾。 +``` +// Data source. +int[] scores = [90, 71, 82, 93, 75, 82]; + +// Query Expression. +IEnumerable scoreQuery = //query variable + from score in scores //required + where score > 80 // optional + orderby score descending // optional + select score; //must end with select or group + +// Execute the query to produce the results +foreach (var testScore in scoreQuery) +{ + Console.WriteLine(testScore); +} + +// Output: 93 90 82 82 +``` + +## 第一步安装Entitu Framework Core +``` +dotnet add package Microsoft.EntityFrameworkCore.SqlServer +``` +## 第二创建实体数据类型(数据模型) +``` +Model.cs +``` +## 第三定义构成模型的上下文类和实体类 +``` + +``` + +## 创建数据库上下文,配置好 +``` +- 先创建一个控制台程序 + + +- 重写一个函数 : OnConfiguring +``` +## 进行数据迁移(2个前提 :1.程序不能有编译错误;2.程序必须停止运行) +``` +dotnet ef migrations add 名字 +例如:dotnet ef migrations add InitialCreate +``` +## 将生成的数据迁移文件,同步更新到数据库 +``` +dotnet ef database update +``` + +``` +到这里要先在文件Blog.csproj中出现 +```c# + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + +``` +## 5.将上一步生成的迁移文件,更新到数据库:dotnet ef database update +`dotnet ef database update` +(PS:需要保证连接字符串正确无误,包括用户名、密码等,数据库打开,并且允许远程连接) + +- 结束后,在文件夹中会出现Migrations文件,就可以在数据库中看到你保存的数据 +\ No newline at end of file + +``` \ No newline at end of file