.net core api

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Cors;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.CodeAnalysis.CSharp.Syntax;
  9. using Microsoft.Extensions.Caching.Memory;
  10. using Weeko3_Test.BLL.IBLL;
  11. using Weeko3_Test.Model;
  12.  
  13. namespace Weeko3_Test.Api.Controllers
  14. {
  15. [Route("api/Product")]
  16. [ApiController]
  17. [EnableCors("any")]
  18. public class ProductController : ControllerBase
  19. {
  20. /// <summary>
  21. /// 依赖注入
  22. /// </summary>
  23. private readonly IProductBll _bll;
  24.  
  25. public ProductController(IProductBll bll)
  26. {
  27. _bll = bll;
  28. }
  29. [Route("SelectList")]
  30. [HttpGet]
  31. ////[EnableCors("any")]
  32. public async Task<PageViewModel> SelectList(int pageIndex = 1, int pageSize = 5)
  33. {
  34. List<ProductInfoModel> list = await Task.Run(() => { return _bll.Select(); });
  35. int count = list.Count;
  36. var v = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);
  37. PageViewModel model = new PageViewModel();
  38. model.PageTotal = int.Parse(Math.Ceiling(decimal.Parse(count.ToString()) / pageSize).ToString());
  39. model.Models = v.ToList();
  40. return model;
  41. }
  42.  
  43. }
  44. }

cshtml

  1. <link href="~/css/site.css" rel="stylesheet" />
  2. <script src="~/lib/jquery/dist/jquery.js"></script>
  3.  
  4. <table class="layui-table" lay-size="sm">
  5. <colgroup>
  6. <col width="150">
  7. <col width="200">
  8. <col width="200">
  9. <col width="200">
  10. <col width="200">
  11. </colgroup>
  12. <thead>
  13. <tr>
  14. <th>产品名称</th>
  15. <th>投资金额</th>
  16. <th>投资收益</th>
  17. <th>投资时间</th>
  18. <th>投资编号</th>
  19. </tr>
  20. </thead>
  21. <tbody id="tb">
  22. </tbody>
  23. </table>
  24. <div>
  25. <div>
  26. <input id="btn_First" type="button" value="首页" />
  27. <input id="btn_Pro" type="button" value="上一页" />
  28. <input id="btn_Next" type="button" value="下一页" />
  29. <input id="btn_Last" type="button" value="尾页" />
  30.  
  31. </div>
  32. </div>
  33. <script>
  34. var pageSize = 5;
  35. var pageIndex = 1;
  36. var count = 0;
  37. $(function () {
  38. Show();
  39. })
  40. function Show() {
  41. $.ajax({
  42. url: "http://localhost:51457/api/product/SelectList",
  43. type: "get",
  44. dataType: "json",
  45. data: { pageIndex: pageIndex, pageSize: pageSize },
  46. success: function (data) {
  47. count = data.pageTotal;
  48. $('#tb').empty();
  49. //循环遍历
  50. $.each(data.models, function (index, item) {
  51. //定义变量
  52. var tr = '';
  53. //开始拼接
  54. tr += '<tr class="active">';
  55. tr += '<td>' + item.product_Name + '</td>';
  56. tr += '<td>' + item.startMoney + '元' + '</td> ';
  57. tr += '<td>' + item.produce_ShouYi + '元' + '</td>';
  58. tr += '<td>' + item.tCreateDate + '</td> ';
  59. tr += '<td>' + item.product_No + '</td>';
  60. tr += '</tr>';
  61. //尾部添加
  62. $('#tb').append(tr);
  63. })
  64. }
  65. });
  66. }
  67.  
  68. //首页
  69. $('#btn_First').click(function () {
  70. pageIndex = 1;
  71. Show();
  72.  
  73. })
  74. //上一页
  75. $('#btn_Pro').click(function () {
  76. if (pageIndex - 1 < 1) {
  77. pageIndex = 1;
  78. alert("到顶了");
  79. } else {
  80. pageIndex--;
  81. Show();
  82. }
  83.  
  84. })
  85. //下一页
  86. $('#btn_Next').click(function () {
  87. if (pageIndex + 1 > count) {
  88. pageIndex = count;
  89. alert("到底了");
  90. } else {
  91. pageIndex++;
  92. Show();
  93. }
  94. })
  95. //尾页
  96. $('#btn_Last').click(function () {
  97. pageIndex = count;
  98. Show();
  99. })
  100.  
  101. </script>

.Net core Api后台获取数据,异步方法中,数据需采用Linq分页的更多相关文章

  1. ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据

    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案   ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...

  2. .NET Core API后台架构搭建

    ASP.NET Core API后台架构搭建 项目文件:https://files.cnblogs.com/files/ZM191018/WebAPI.zip 本篇可以了解到: 依赖注入 Dapper ...

  3. [转载]JAVA获取word表格中数据的方案

    上一个项目的开发中需要实现从word中读取表格数据的功能,在JAVA社区搜索了很多资料,终于找到了两个相对最佳的方案,因为也得到了不少网友们的帮助,所以不敢独自享用,在此做一个分享. 两个方案分别是: ...

  4. [原创]JAVA获取word表格中数据的方案

    上一个项目的开发中需要实现从word中读取表格数据的功能,在JAVA社区搜索了很多资料,终于找到了两个相对最佳的方案,因为也得到了不少网友们的帮助,所以不敢独自享用,在此做一个分享. 两个方案分别是: ...

  5. 【记录】mybatis中获取常量类中数据

    部分转载,已注明来源: 1.mybatis中获取常量类中数据 <update id="refuseDebt"> UPDATE dt_debt a SET         ...

  6. python xlrd 模块(获取Excel表中数据)

    python xlrd 模块(获取Excel表中数据) 一.安装xlrd模块   到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了pyt ...

  7. MySQL查询数据表中数据记录(包括多表查询)

    MySQL查询数据表中数据记录(包括多表查询) 在MySQL中创建数据库的目的是为了使用其中的数据. 使用select查询语句可以从数据库中把数据查询出来. select语句的语法格式如下: sele ...

  8. .Net NPOI 上传excel文件、提交后台获取excel里的数据

    1.导入NPOI.dll 2.添加类NPOIExcel.cs using System; using System.Collections.Generic; using System.Text; us ...

  9. scrapy获取当当网中数据

    yield 1. 带有 yield 的函数不再是一个普通函数,而是一个生成器generator,可用于迭代 2. yield 是一个类似 return 的关键字,迭代一次遇到yield时就返回yiel ...

随机推荐

  1. Java中this和super的使用

    区别 区别点 this super 访问属性 访问本类中的属性,如果本类没有,则从父类继续查找 访问父类中的属性 调用方法 访问本类中的方法,如果本类没有,则从父类继续查找 直接访问父类的方法 调用构 ...

  2. 02 HTML标签

    2. HTML标签 1. HTML简介 用户使用浏览器打开网页看到结果的过程就是:浏览器将服务端的文本文件(即网页文件)内容下载到本地,然后打开显示的过程. 而文本文件的文档结构只有空格和黄航两种组织 ...

  3. Solution -「多校联训」假人

    \(\mathcal{Description}\)   Link.   一种物品有 长度 和 权值 两种属性,现给定 \(n\) 组物品,第 \(i\) 组有 \(k_i\) 个,分别为 \((1,a ...

  4. LRU缓存及实现

    一.淘汰策略 缓存:缓存作为一种平衡高速设备与低速设备读写速度之间差异而引入的中间层,利用的是局部性原理.比如一条数据在刚被访问过只有就很可能再次被访问到,因此将其暂存到内存中的缓存中,下次访问不用读 ...

  5. 【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题

    问题描述 App Service for Linux 资源创建完成后,通过FTP方式把 .jar包(logdemo.jar)包上传到 /site/wwwroot/ 文件夹后,在App Service的 ...

  6. MyBatis功能点二:从责任链设计模式的角度理解插件实现技术

    MyBatis允许对其四大组件(Executor,StatementHandler,ParameterHandler, ResultSetHandler)进行增强处理.在创建四大组件对象的时候 1.每 ...

  7. 【转】浅谈 Integer 类

    突然发现自己对Integer i = 10;这种语法不太明白,于是乎有了这篇文章,那么在讲解 Integer 之前,我们先看下面这段代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  8. ctf平台

    CTF靶场 蓝鲸安全:http://whalectf.xin bugku:https://ctf.bugku.com XCTF攻防世界:https://adworld.xctf.org.cn/ i春秋 ...

  9. IPC$管道的利用与远程控制

    实验目的 通过实验了解IPC$攻击的原理与方法. 实验原理 IPC$攻击的相关原理 IPC$(Internet Process Connection)是共享"命名管道"的资源,它是为了让进程间通信而开 ...

  10. 智能脚本工具(Smart scripts)测试应用

    如果你是一位网络测试人员,您的工作中是否有出现过以下困扰呢? · 重复机械式的测试有时让你觉得工作是如此的枯燥乏味!· 只增不减的测试用例让你下班越来越晚!· 请求老板招人,人却永远不够用! 但值得庆 ...