版本:1.2.41
问题描述:在springboot+mybatis中使用PageHelper插件,最后返回json数据的时候,没有正确解析出来PageInfo对象内的list对象
我的写法是这样的:
List<HashMap> detailList = (mybatis查询结果);
PageInfo<HashMap> pageInfo = new PageInfo(detailList);
Map<String,Object> resultMap = new HashMap();
resultMap.put("page",pageInfo);
resultMap.put("detailList",detailList);
return JSONObject.toJSONString(resultMap);
最后的结果:{"page":{"endRow":2,"firstPage":1,"hasNextPage":false,"hasPreviousPage":false,"isFirstPage":true,"isLastPage":true,"lastPage":1,"list":[{"$ref":"$.detailList[0]"},{"$ref":"$.detailList[1]"}],"navigatePages":8,"navigatepageNums":[1],"nextPage":0,"pageNum":1,"pageSize":10,"pages":1,"prePage":0,"size":2,"startRow":1,"total":2}}
detailList解析正确就不贴了
Map<String,Object> resultMap = new HashMap();
resultMap.put("page",pageInfo);
resultMap.put("detailList",detailList);
logger.info("pageInfo:{}",JSONObject.toJSONString(pageInfo));
logger.info("list:{}",JSONObject.toJSONString(pageInfo.getList()));
for(HashMap h : pageInfo.getList()) {
logger.info("h:{}",h);
}
这样输出都是正常的……
但是
return JSONObject.toJSONString(resultMap);
就是解析不出来……
同问题,应该是序列化深度的问题,但是不知道怎么改。
已解决,toJSONString后面加SerializerFeature.DisableCircularReferenceDetect就好了,被循环检测阻止序列化了。 @lxl94999
厉害,又学会一招
Most helpful comment
已解决,toJSONString后面加SerializerFeature.DisableCircularReferenceDetect就好了,被循环检测阻止序列化了。 @lxl94999