前端返回 r e f : ref: ref:returnlist.data[0].line的数据问题
前端返回 r e f : ref: ref:returnlist.data[0].line的数据问题
后端数据打印都是对的,前端显示却不知道是什么鬼东西,
上网查询了之后说是对象的重复引用的问题,
那什么是重复引用?
重复引用就是一个集合/对象中的多个元素/属性同时引用同一对象,循环引用就是集合/对象中的多个元素/属性存在相互引用导致循环。
解决
网上的方法是使用JSONObject.toJSONString(date,SerializerFeature.DisableCircularReferenceDetect);//date是结果,(通过禁止循环引用),但是我使用时说SerializerFeature is not define(不知道是不是用错了地方)
之前的代码
list = logisticsLocalDao.logisticslocas(param);
for(Map<String,Object> temp:list) {
List lines = new ArrayList<>();
lines = logisticsLocalDao.lines(temp);
if(lines != null && lines.size()>0) {
temp.put("lines", lines);
}else
if(temp.get("line") != null && !temp.get("line").equals("")) {
String line = temp.get("line").toString();
String [] liness = line.split(",");
for(int i=0; i<liness.length;i++) {
Map map = new HashMap<>();
String str = liness[i];
map.put("startpro", "");
map.put("startplace", "");
map.put("endpro", "");
map.put("endplace", "");
map.put("price", "0");
map.put("pricevolume", "0");
map.put("oid", "");
map.put("logisticslocalid",temp.get("logisticslocalid"));
map.put("startplacetow", str.substring(0,str.indexOf('到')));
map.put("endplacetow", str.substring(str.indexOf('到')+1));
lines.add(map);
}
temp.put("lines", lines);
}else {
temp.put("lines", "");
}
}
我觉得可能问题出现在lines的引用上,于是重新new了一个新的list,就可以了
List lines = new ArrayList<>();
lines = logisticsLocalDao.lines(temp);
if(lines != null && lines.size()>0) {
temp.put("lines", lines);
}else {
List lines1 = new ArrayList<>();
if(temp.get("line") != null && !temp.get("line").equals("")) {
String line = temp.get("line").toString();
String [] liness = line.split(",");
for(int i=0; i<liness.length;i++) {
Map map = new HashMap<>();
String str = liness[i];
map.put("startpro", "");
map.put("startplace", "");
map.put("endpro", "");
map.put("endplace", "");
map.put("price", "0");
map.put("pricevolume", "0");
map.put("oid", "");
map.put("logisticslocalid",temp.get("logisticslocalid"));
map.put("startplacetow", str.substring(0,str.indexOf('到')));
map.put("endplacetow", str.substring(str.indexOf('到')+1));
lines1.add(map);
}
temp.put("lines", lines1);
}else {
temp.put("lines", "");
}
}
}