zoukankan      html  css  js  c++  java
  • 批量添加代码,修改,删除控制器部分

     public class HomeController : Controller
        {
            bll s = new bll();引用

    //显示
            public ActionResult studentlist()
            {
                return View();
            }
            [HttpPost]
            public ActionResult StudentList1()
            {
                var result = new BLL.bll().Show();
                return Json(result);
            }

    添加
            [HttpPost]
            public JsonResult Studentadd(string a)
            {
                 a = a.TrimEnd('|');
                string[] ste = a.Split('|');
                if (ste == null||ste.Length==0)
                {
                    return Json(new
                    {
                        code=0,
                        msg="字符串异常"
                    });

                }
                else
                {
                    List<model> studentlist = new List<model>();
                    foreach (var item in ste)
                    {
                        string[] y = item.Split(',');
                        if (y != null || y.Length > 0)
                        {
                            model si = new model();
                            si.Sxuehao = y[0];
                            si.SNAME = y[1];
                            si.SAGE = y[2];
                            studentlist.Add(si);

                        }

                    }
                    var i = s.addlist(studentlist);
                    if (i > 0)
                    {
                        return Json(new
                        {
                            code = 1,
                            msg = "成功"
                        });
                    }
                    else
                    {
                        return Json(new
                        {
                            code = 0,
                            msg = "失败"
                        });

                    }

                }
               

            }

    删除
            public JsonResult del(int id)
            {
                var result = new BLL.bll().del(id);
                if (result > 0)
                {
                    return Json(1);
                }
                else
                {
                    return Json(0);
                }

            }

    修改
            public JsonResult update(model stu)
            {
                var result = s.uptate(stu);
                if (result > 0)
                {
                    return Json(new
                    {
                        code = 1,
                        msg = "成功"
                    });

                }
                else
                {
                    return Json(new
                    {
                        code = 0,
                        msg = "失败"
                    });
                }
            }
            public ActionResult About()
            {
                ViewBag.Message = "Your application description page.";

                return View();
            }

            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";

                return View();
            }
        }

  • 相关阅读:
    FreeMarker MyEclipse IDE
    Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring
    Mybatis SqlSessionTemplate 源码解析
    Mybatis Interceptor 拦截器原理 源码分析
    MyBatis Mapper 接口如何通过JDK动态代理来包装SqlSession 源码分析
    MyEclipse SVN 下面切换用户的解决方案
    SpringMVC 多个数据源 配置多个事物管理器 Multiple Transaction Managers
    Activiti 获取定义
    [No000066]python各种类型转换-int,str,char,float,ord,hex,oct等
    [No000065]python 获取当前时间
  • 原文地址:https://www.cnblogs.com/danhuangjun/p/7879229.html
Copyright © 2011-2022 走看看