• 使用bean字典的作为后端表格的数据源

    • 注意点:直接将外层的JSONObject对象 data 作为new Pager()的参数,不需要去新建一个result的JSONObject对象,注意是否有分页需求
image-20231007102747744
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//重写bean字典的dictQuery方法
@Override
public Pager dictQuery(Map<String, Object> params) {
log.info("测试后端表格");
//创建列的JSONArray
JSONArray columns = new JSONArray();
//包含表头和数据索引
columns.add(createColumn("title","姓名","dataIndex", "grid_name"));
columns.add(createColumn("title","年龄","dataIndex", "grid_age"));
columns.add(createColumn("title","生日","dataIndex", "grid_birthday"));
//创建表格中数据的JSONArray
JSONArray data = new JSONArray();
//每一行包含数据索引 以及对应的值,即为 数据索引,数据值 的键值对
data.add(createColumn("grid_name", "张三", "grid_age","12", "grid_birthday","2000-10-01","grid_id","11"));
data.add(createColumn("grid_name", "李四", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "12"));
data.add(createColumn("grid_name", "王五", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "13"));
data.add(createColumn("grid_name", "赵六", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "15"));
//创建外层的JSONObject对象resdata
JSONObject resdata = new JSONObject();
resdata.put("data", data);
resdata.put("columns", columns);
//直接将resdata作为result,创建Pager对象,根据分页需求设置对应的size,No,count
return new Pager(resdata,10,1,1);
}
//创建后端表格数据列的方法
private JSONObject createColumn(String ... key) {
JSONObject object = new JSONObject();
for (int i = 0; i < key.length; i+=2) {
object.put(key[i], key[i+1]);
}
return object;
}
  • 使用http字典的作为后端表格的数据源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@RequestMapping("/data")
public JSONResult getData(String parameterValue,
String dataSourceInfo,
Integer startPage,
Integer pageSize){
JSONArray columns = new JSONArray();
columns.add(createColumn("title","姓名","dataIndex", "grid_name"));
columns.add(createColumn("title","年龄","dataIndex", "grid_age"));
columns.add(createColumn("title","生日","dataIndex", "grid_birthday"));
JSONArray data = new JSONArray();
data.add(createColumn("grid_name", "张三", "grid_age","12", "grid_birthday","2000-10-01","grid_id","11"));
data.add(createColumn("grid_name", "李四", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "12"));
data.add(createColumn("grid_name", "王五", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "13"));
data.add(createColumn("grid_name", "赵六", "grid_age","12", "grid_birthday","2000-10-01", "grid_id", "15"));

JSONObject resdata = new JSONObject();
resdata.put("data", data);
resdata.put("columns", columns);
JSONObject res = new JSONObject();
res.put("data", resdata);
res.put("totalCount", 10);
res.put("pageNo", 1);


return new JSONResult().setResult(res);
}

private JSONObject createColumn(String ... key) {
JSONObject object = new JSONObject();
for (int i = 0; i < key.length; i+=2) {
object.put(key[i], key[i+1]);
}
return object;
}