首页 > 移动平台 > 详细

API + MVC +Dapper + Linq + SJ 实现分页查询

时间:2020-08-06 09:18:11      阅读:256      评论:0      收藏:0      [点我收藏+]

后台方法

using (SqlConnection conn = new SqlConnection(str))
{
  string sql = $"select * from Goods where 1 = 1";
  if (!string.IsNullOrWhiteSpace(name))
  {
    sql += $"and Name like ‘%{name}%‘";
  }
  var list = conn.Query<ModelInfo>(sql);
  Pages pag = new Pages();
  pag.ModelInfos = list.OrderBy(x => x.ID)
    .Skip((index - 1) * size)
    .Take(size).ToList();
  var count = list.Count();
  pag.Page = count / size + (count % size == 0 ? 0 : 1);
  return pag;
}

 

public class Pages
{
  public List<类名> 类别名{ get; set; }
  public int Page { get; set; }
}

 

前台代码

<div>
  <input id="Button1" onclick="first()" type="button" value="首页" />
  <input id="Button1" onclick="prev()" type="button" value="上一页" />
  <input id="Button1" onclick="next()" type="button" value="下一页" />
  <input id="Button1" onclick="last()" type="button" value="尾页" />
</div>

 

<script>
  var index1 = "";
  var pagecount = "";
  function first() {
    index1 = 1;
    log(index1);
  }
  function prev() {
    index1--;
    if (index1 == 0) {
      index1 = 1;
    }
    log(index1);
  }
  function next() {
    index1++;
    if (index1 > pagecount) {
      index1 = pagecount;
    }
    log(index1);
  }
  function last() {
    log(pagecount);
  }
</script>

API + MVC +Dapper + Linq + SJ 实现分页查询

原文:https://www.cnblogs.com/Ai-Dou/p/13444136.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!