From f5d2330369b62dd5ad2276fc45ca4c800b323f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E7=BE=A4?= Date: Sun, 29 Dec 2024 17:02:49 +0800 Subject: [PATCH] =?UTF-8?q?20241223/25=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3-\344\274\252\346\225\260\347\273\204.md" | 11 ++ ...37\345\210\206\346\225\260\350\241\250.md" | 111 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 "\350\222\213\347\276\244/20241223-\344\274\252\346\225\260\347\273\204.md" create mode 100644 "\350\222\213\347\276\244/20241225-\345\255\246\347\224\237\345\210\206\346\225\260\350\241\250.md" diff --git "a/\350\222\213\347\276\244/20241223-\344\274\252\346\225\260\347\273\204.md" "b/\350\222\213\347\276\244/20241223-\344\274\252\346\225\260\347\273\204.md" new file mode 100644 index 0000000..53c4370 --- /dev/null +++ "b/\350\222\213\347\276\244/20241223-\344\274\252\346\225\260\347\273\204.md" @@ -0,0 +1,11 @@ +### mvc伪数组 +- 数组是一种数据结构,用于存储固定大小的同类型元素集合。 +- 数组的大小在声明时确定,并且之后不能改变(除非使用特定的方法,如Array.Resize,但这会创建一个新的数组)。 +- 数组通过索引访问元素,索引从0开始。 + +- List作为伪数组: +- List是C#中最常用的伪数组实现。 +- 它提供了与数组类似的索引访问方式,但List的大小是动态的,可以根据需要增加或减少元素。 +List还提供了许多方便的方法,如Add、Remove、Insert等,用于操作集合中的元素。 + +- Dictionary或SortedDictionary。 \ No newline at end of file diff --git "a/\350\222\213\347\276\244/20241225-\345\255\246\347\224\237\345\210\206\346\225\260\350\241\250.md" "b/\350\222\213\347\276\244/20241225-\345\255\246\347\224\237\345\210\206\346\225\260\350\241\250.md" new file mode 100644 index 0000000..59b021e --- /dev/null +++ "b/\350\222\213\347\276\244/20241225-\345\255\246\347\224\237\345\210\206\346\225\260\350\241\250.md" @@ -0,0 +1,111 @@ +```js +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using StudentManger.Models; + +namespace StudentManger.Controllers; + +public class StudentController:Controller{ + + //数据库 +private readonly StudentsContext _db; +public StudentController() +{ + _db=new StudentsContext(); +} + + public IActionResult Index(){ + var list=_db.Students.ToList(); + return View(list); + } + //新增 + public IActionResult Create(){ + return View(); + + } + [HttpPost] + public IActionResult Create(Students input){ + _db.Students.Add(input); + _db.SaveChanges(); + return RedirectToAction("Index"); + + } + + //编辑 + public IActionResult Edit(int id){ + var cont=_db.Students.FirstOrDefault(x=>x.Id==id); + return View(cont); + + } + [HttpPost] + public IActionResult Edit(Students input){ + var cont=_db.Students.FirstOrDefault(x=>x.Id==input.Id); + if(cont==null){ + return NotFound(); + } + cont.Age=input.Age; + cont.StudentName=input.StudentName; + _db.SaveChanges(); + return RedirectToAction("Index"); + + } + //删除 + // public IActionResult Delete(){ + // return View(); + + // } + // public IActionResult DeleteOther(){ + // return View(); + + // } + public IActionResult Delete(int id) + { + var cont = _db.Students.FirstOrDefault(x=>x.Id==id); + + return View(cont); + } + public IActionResult DeleteOther(int id) + { + var cont = _db.Students.FirstOrDefault(x=>x.Id==id); + if(cont==null) + { + return NotFound(); + } + _db.Students.Remove(cont); + _db.SaveChanges(); + + return RedirectToAction("Index"); + + } +} +``` +```js +namespace StudentManger.Models; + +public class Students{ + +public int Id{get;set;} +public int Age{get;set;} +public string StudentName{get;set;}=null!; + +} + +``` +```js +// using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +namespace StudentManger.Models; + + +public class StudentsContext:DbContext{ + +public DbSet Students{get;set;}=null!; + +protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){ + base.OnConfiguring(optionsBuilder); + var contionString=$"server=.;database=Studentjq;uid=sa;pwd=123456;TrustServerCertificate=true;"; + optionsBuilder.UseSqlServer(contionString); +} +} + +``` \ No newline at end of file -- Gitee