zoukankan      html  css  js  c++  java
  • 分页

    //DAL层

    public List<studentModel> show(string name = "",int index=1,int size=2)
    {
    int start = (index - 1) * size + 1;
    int end = start + size - 1;
    string sql = string.Format("select * from (select *,ROW_NUMBER()over(order by id)px from student where name like '%{0}%')t where t.px between {1}and {2}",name,start,end);
    var n = db.GetDataTable(sql);
    var list = JsonConvert.SerializeObject(n);
    var table = JsonConvert.DeserializeObject<List<studentModel>>(list);
    return table;
    }
    public int count()
    {
    string sq = "select count(id) from student";
    var i = db.ExecuteScalar(sq);
    return i;
    }

    //控制器
    public ActionResult Index(string name = "",int index=1,int size=2)
    {
    ViewBag.index = index;
    int count = st.count();
    ViewBag.count = Math.Ceiling(count * 1.0 / size);
    var n = st.show(name,index,size);
    return View(n);
    }

    ////显示视图

    <input id="index" type="hidden" value="@ViewBag.index" />
    <input id="count" type="hidden" value="@ViewBag.count" />
    <input id="Button1" type="button" value="首页" onclick="sy()" />
    <input id="Button1" type="button" value="上一页" onclick="syy()" />
    <input id="Button1" type="button" value="下一页" onclick="xyy()" />
    <input id="Button1" type="button" value="尾页" onclick="wy()" />

    <script>
    var index = 1;
    var size = 2;
    function sy() {
    location.href = "/student/Index?index=1&size=2";
    }
    function syy() {
    index = $("#index").val();
    index <= 1 ? 1 : index--;
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    function xyy() {
    index = $("#index").val();
    var count = $("#count").val();
    index >= count ? count : index++;
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    function wy() {
    index = $("#count").val();
    location.href = "/student/Index?index=" + index + "&size=" + size + "";
    }
    </script>

  • 相关阅读:
    Java 中日常使用的 IO 流总结
    NIO 实现非阻塞 Socket 通讯
    Java NIO 的简单介绍和使用
    常用设计模式 -- 一分钟就能学会的门面模式(外观模式)
    Java日志框架介绍和 Slf4j 使用
    Linux学习一
    JavaScript-数组
    javascript
    idea 快捷键汇总
    正则表达式
  • 原文地址:https://www.cnblogs.com/gaoyuhui/p/10957298.html
Copyright © 2011-2022 走看看