Home > Java > Java Tutorial > body text

Java server-side paging processing and datatables with query condition examples

黄舟
Release: 2017-06-04 09:12:48
Original
1633 people have browsed it

本篇文章主要介绍了datatables 带查询条件java服务端分页处理实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

使用datatables自带后台查询

前台代码:

















  

Name Position
Copy after login

Java代码如下,使用spring的 @ResponseBody将结果转换成json格式返回给前台

@RequestMapping(value="/datatablesTest", method=RequestMethod.GET)
  @ResponseBody
  public DatatablesViewPage datatablesTest(HttpServletRequest request){
//获取分页控件的信息
    String start = request.getParameter("start");
    System.out.println(start);
        String length = request.getParameter("length");
    System.out.println(length);
//获取前台额外传递过来的查询条件
    String extra_search = request.getParameter("extra_search");
    System.out.println(extra_search);
        //随便组织的查询结果
    List list = new ArrayList();
    Alarm alarm = new Alarm();
    alarm.setLevel(1);
    alarm.setTotal(100L);
    list.add(alarm);
    alarm = new Alarm();
    alarm.setLevel(2);
    alarm.setTotal(100L);
    list.add(alarm);


    DatatablesViewPage view = new DatatablesViewPage();
    view.setiTotalDisplayRecords(100);
    view.setiTotalRecords(100);

    view.setAaData(list);
    return view;
  }
Copy after login

DatatablesViewPage的声明如下:

public class DatatablesViewPage {

  private List aaData; //aaData 与datatales 加载的“dataSrc"对应
  private int iTotalDisplayRecords; 
  private int iTotalRecords;
  public DatatablesViewPage() {

  }
//get set方法 此处省略

}
Copy after login

在后台传输数据也可以用fastjson ;

@ResponseBody
  @RequestMapping("/datatable2")
  public JSON getTable2(String aoData){
    String sEcho = "";// 记录操作的次数 每次加1
    String iDisplayStart = "";// 起始
    String iDisplayLength = "";// size
    String sSearch = "";// 搜索的关键字
    int count = 1 ; //查询出来的数量
    JSONArray alldata = JSON.parseArray(aoData);
    for (int i = 0; i  listMap = new HashMap();
    List list = new ArrayList();
    list.add(u1);
    listMap.put("iTotalRecords",count);
    listMap.put("sEcho",Integer.parseInt(sEcho)+1);
    listMap.put("iTotalDisplayRecords",count);
    listMap.put("aaData",list);
    return (JSON)JSON.toJSON(listMap);
  }
Copy after login

The above is the detailed content of Java server-side paging processing and datatables with query condition examples. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!