返回的json(siteList)在数据库没有一条记录,siteList冒号后的值跟[]

来源:互联网 发布:遛99遛弯淘宝区怎么样 编辑:程序博客网 时间:2024/05/17 23:51

 recordList为空(数据库没有一条记录),recordList:后面的值是[],下图就是postman测得的返回值

//hashMap.get("data").toString()拿到的是[],反序列化list1值为null ,遍历为null的list集合是不会抛异常的

ArrayList<String> list = new ArrayList<>();//size为0的list,可以遍历(但不进里面的方法),不抛空指针异常
ArrayList<String> list = null;//遍历抛空指针异常,你没list的杯子

List<InspectionRecords> list1 = JSON.parseArray(hashMap.get("data").toString(), InspectionRecords.class);for (InspectionRecords inspectionRecord : list1) {    list.add(inspectionRecord);}return new RespInspectionRecords(list);//将返回对象的内容放到构造里




阅读全文
0 0