jquery datatable background encapsulation data sample code_jquery
1. Data conversion class
public class DataTableReturnObject { private int iTotalRecords; private int iTotalDisplayRecords; private String sEcho; private String[][] aaData; public DataTableReturnObject(int totalRecords, int totalDisplayRecords, String echo, String[][] d) { this.setiTotalRecords(totalRecords); this.setiTotalDisplayRecords(totalDisplayRecords); this.setsEcho(echo); this.setAaData(d); } public void setiTotalRecords(int iTotalRecords) { this.iTotalRecords = iTotalRecords; } public int getiTotalRecords() { return iTotalRecords; } public void setiTotalDisplayRecords(int iTotalDisplayRecords) { this.iTotalDisplayRecords = iTotalDisplayRecords; } public int getiTotalDisplayRecords() { return iTotalDisplayRecords; } public void setsEcho(String sEcho) { this.sEcho = sEcho; } public String getsEcho() { return sEcho; } public void setAaData(String[][] aaData) { this.aaData = aaData; } public String[][] getAaData() { return aaData; } }
2 help classes
public class BaseController { protected JSONResponse successed(Object obj) { JSONResponse ret = new JSONResponse(); ret.setSuccessed(true); ret.setReturnObject(obj); return ret; } }
3. Implementation class
public JSONResponse searchList(HttpServletRequest request , HttpServletResponse response ,String sEcho) throws Exception { //convertToMap定义于父类,将参数数组中的所有元素加入一个HashMap Map<Object, Object> objQueryMap = new HashMap<Object, Object>(); String jsondata = request.getParameter("aoData"); JSONArray jsonarray = JSONArray.fromObject(jsondata); String strDisplayStart =""; String strDisplayLength=""; String[] arrayColumen = new String[new JSONUser().toArray().length]; int strSortId = 0; String strSort = ""; for(int i=0;i<jsonarray.size();i++) //从传递参数里面选出待用的参数 { JSONObject obj=(JSONObject)jsonarray.get(i); String strName = (String)obj.get("name"); String strValue = obj.get("value").toString(); if(strName.equals("sEcho")){ sEcho=strValue; } if(strName.equals("iDisplayStart")) { strDisplayStart=strValue; } if(strName.equals("iDisplayLength")) { strDisplayLength=strValue; } if(strName.equals("sColumns")){ arrayColumen = obj.get("value").toString().split(","); } if(strName.startsWith("iSortCol_")){ strSortId = Integer.parseInt(strValue) ;//排序列数 } if(strName.startsWith("sSortDir_")){ strSort = strValue;//排序的方向 "desc" 或者 "asc". } } Map<Object, Object> params = new HashMap<Object, Object>() ; try { params = managerService.getUserList(参数); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } String count = (String)params.get("COUNT");//总数 String[][] strData = (String[][])params.get("AO_DATA");//当前页显示的集合 return successed(new DataTableReturnObject(Integer.parseInt(count) , Integer.parseInt(count), sEcho, strData)); }
4. Query method
public Map<Object, Object> getUserList(Map<Object, Object> queryParams) throws Exception { String iCount = 总记录数; // 将查询结果转换为一个二维数组 String[][] data = {}; if (lstUser != null && lstUser.size() > 0) { int record = lstUser.size(); data = new String[record][]; for (int i = 0; i < lstUser.size(); i++) { User objUser = (User) lstUser.get(i); JSONUser jsonUser = new JSONUser(); BeanUtils.copyProperties(jsonUser, objUser); data[i] = jsonUser.toArray(); } } queryParams.clear();// 情况map,重新设值使用 queryParams.put("AO_DATA", data); queryParams.put("COUNT", iCount); return queryParams; }
Note that the attributes of the stored array object must maintain the same number of columns as the columns displayed on the front-end page

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



According to news from this site on April 17, TrendForce recently released a report, believing that demand for Nvidia's new Blackwell platform products is bullish, and is expected to drive TSMC's total CoWoS packaging production capacity to increase by more than 150% in 2024. NVIDIA Blackwell's new platform products include B-series GPUs and GB200 accelerator cards integrating NVIDIA's own GraceArm CPU. TrendForce confirms that the supply chain is currently very optimistic about GB200. It is estimated that shipments in 2025 are expected to exceed one million units, accounting for 40-50% of Nvidia's high-end GPUs. Nvidia plans to deliver products such as GB200 and B100 in the second half of the year, but upstream wafer packaging must further adopt more complex products.

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

This website reported on July 9 that the AMD Zen5 architecture "Strix" series processors will have two packaging solutions. The smaller StrixPoint will use the FP8 package, while the StrixHalo will use the FP11 package. Source: videocardz source @Olrak29_ The latest revelation is that StrixHalo’s FP11 package size is 37.5mm*45mm (1687 square millimeters), which is the same as the LGA-1700 package size of Intel’s AlderLake and RaptorLake CPUs. AMD’s latest Phoenix APU uses an FP8 packaging solution with a size of 25*40mm, which means that StrixHalo’s F

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

By encapsulating code, C++ functions can improve GUI development efficiency: Code encapsulation: Functions group code into independent units, making the code easier to understand and maintain. Reusability: Functions create common functionality that can be reused across applications, reducing duplication and errors. Concise code: Encapsulated code makes the main logic concise and easy to read and debug.

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
