dapper mysql 分页_Dapper分页查询

//api

//数据库连接字符串

string connstr = "Data Source=.;Initial Catalog=Month6;Integrated Security=True";

APIFileHelp help = new APIFileHelp();

//上传文件

[HttpPost]

public FileResult UpLoad()

{

return help.UpLoad();

}

//分页导出

[HttpGet]

public void Export1(int index, int size = 2)

{

SqlConnection conn = new SqlConnection(connstr);

var list = conn.Query("select * from Goods").ToList();

list = list.OrderBy(x => x.GId).Skip((index - 1) * size).Take(size).ToList();

Dictionary dic = new Dictionary();

dic.Add("GId", "商品编号");

dic.Add("GName", "商品名称");

dic.Add("GColor", "商品颜色");

dic.Add("GSize", "商品尺码");

dic.Add("GPrice", "商品价格");

help.ExportExcel("a.xls", list, dic);

}

//显示商品

[HttpGet]

public PageDate GetGoods(int index, int size)

{

SqlConnection conn = new SqlConnection(connstr);

var list = conn.Query("select * from Goods").ToList();

PageDate page = new PageDate();

page.List = list.OrderBy(x => x.GId).Skip((index - 1) * size).Take(size).ToList();

var count = list.Count();

page.PageCount = count / size + (count % size == 0 ? 0 : 1);

return page;

}

导出列表

商品图片商品名称商品颜色商品尺码商品价格操作

var index1 = 0; //获得当前页

var pagecount = 0;

function load(index) {

daoshu();

index1 = index;

$.ajax({

url: "http://localhost:51518/api/Shop/GetGoods2",

data: { index: index, size: 2 },

type: "get",

dataType: "json",

success:

function (d) {

$("#tb").empty();

$(d.List).each(function () {

$("#tb").append(

'

' +

'

localhost:51518'%20+%20this.GImg%20+%20'' +

'

' + this.GName + '' +

'

' + this.GColor + '' +

'

' + this.GSize + '' +

'

' + this.GPrice + '' +

'

 ' +

'

'

)

})

pagecount = d.PageCount;

}

})

}

load(1);

function first() {

index1 = 1;

daoshu();

load(index1);

}

function prev() {

index1--;

if (index1 == 0) {

index1 = 1;

}

daoshu();

load(index1);

}

function next() {

index1++;

if (index1 > pagecount) {

index1 = pagecount;

}

daoshu();

load(index1);

}

function last() {

daoshu();

load(pagecount);

}

//删除

function del(id) {

var obj = {

GId: id

};

$.ajax({

url: "http://localhost:51518/api/Shop/DeleteGood",

data: obj,

type: "post",

dataType: "json",

success:

function (d) {

if (d > 0) {

alert('删除成功!');

load();

}

else {

alert('删除失败!');

}

}

})

}

//修改

function upt(id) {

location.href = "/Default/Update";

document.cookie = id;

}

//导出

function daoshu() {

$("#a").prop("href", "http://localhost:51518/api/Shop/Export1?index=" + index1);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值