Rumah > hujung hadapan web > tutorial js > jquery datatable background enkapsulasi data sampel code_jquery

jquery datatable background enkapsulasi data sampel code_jquery

WBOY
Lepaskan: 2016-05-16 16:40:04
asal
1512 orang telah melayarinya

1. Kelas penukaran data

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; 
} 
}
Salin selepas log masuk

2 kelas bantuan

public class BaseController { 
protected JSONResponse successed(Object obj) { 
JSONResponse ret = new JSONResponse(); 
ret.setSuccessed(true); 
ret.setReturnObject(obj); 
return ret; 
} 
}
Salin selepas log masuk

3. Kelas pelaksanaan

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)); 
}
Salin selepas log masuk

4. Kaedah pertanyaan

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; 
}
Salin selepas log masuk

Perhatikan bahawa atribut objek tatasusunan yang disimpan mesti mempunyai bilangan lajur yang sama seperti yang dipaparkan pada halaman hujung hadapan

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan