现在返回json数据带有分页的数据,将返回data属性数据变更为content,数据不变,key发生变化
说明:如果使用这种方式完成需求,需要创建对象,一个和PageInfo一样的对象,list属性修改为content,其他拷贝过去就行了。
但是,如果数据量10w左右,还是按照这种方式,json转换比较耗时,这种方式虽然麻烦,效率快一点。
@Test
public void t2(){
log.info("需求:k1变为k2,value不变");
Map<String, Object> map = new HashMap<>();
map.put("k1","v1");
log.info("修改前");
for (Map.Entry<String, Object> entry : map.entrySet()) {
log.info("key:【{}】,value:【{}】",entry.getKey(),entry.getValue());
}
String pendingItem = map.get("k1").toString();
map.remove("k1");
map.put("k2",pendingItem);
log.info("修改后");
for (Map.Entry<String, Object> entry : map.entrySet()) {
log.info("key:【{}】,value:【{}】",entry.getKey(),entry.getValue());
}
}
Connected to the target VM, address: ‘127.0.0.1:5463’, transport: ‘socket’
20:12:41.966 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - 需求:k1变为k2,value不变
20:12:41.984 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - 修改前
20:12:41.984 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - key:【k1】,value:【v1】
20:12:41.989 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - 修改后
20:12:41.990 [main] INFO com.geekmice.springbootselfexercise.NoDaoTest - key:【k2】,value:【v1】
Disconnected from the target VM, address: ‘127.0.0.1:5463’, transport: ‘socket’
String listSTR = "{\n" +
"\t\t\"startRow\": 3,\n" +
"\t\t\"navigatepageNums\": [1, 2],\n" +
"\t\t\"prePage\": 1,\n" +
"\t\t\"hasNextPage\": false,\n" +
"\t\t\"nextPage\": 0,\n" +
"\t\t\"pageSize\": 2,\n" +
"\t\t\"endRow\": 3,\n" +
"\t\t\"list\": [{\n" +
"\t\t\t\"teacherName\": \"小2\",\n" +
"\t\t\t\"teacherNo\": \"6\",\n" +
"\t\t\t\"categoryId\": 9999\n" +
"\t\t}],\n" +
"\t\t\"pageNum\": 2,\n" +
"\t\t\"navigatePages\": 8,\n" +
"\t\t\"total\": 3,\n" +
"\t\t\"navigateFirstPage\": 1,\n" +
"\t\t\"pages\": 2,\n" +
"\t\t\"size\": 1,\n" +
"\t\t\"isLastPage\": true,\n" +
"\t\t\"hasPreviousPage\": true,\n" +
"\t\t\"navigateLastPage\": 2,\n" +
"\t\t\"isFirstPage\": false\n" +
"\t}";
JSONObject jsonObject1 = JSONObject.parseObject(listSTR);
Object newList = jsonObject1.get("list");
jsonObject1.remove("list");
jsonObject1.put("content", newList);