先上代码privateJSONArraygetJsonArray(){QueryWrapperkltSoftExamineQueryWrapper=newQueryWrapper<>();kltSoftExamineQueryWrapper.select("平台").groupBy("平台");列表platForms=kltSoftExamineMapper.selectList(kltSoftExamineQueryWrapper);JSONArrayjsonArray=newJSONArray();JSONObjectjsonPlatObject=newJSONObject();platForms.forEach(platForm->{jsonPlatObject.put("plateformCode",platForm.getPlatform());//1jsonPlatObject.put("plateformName","platformName");//2//获取serverListJSONArrayjsonServerListArray=newJSONArray();QueryWrapperkltSoftExamineQueryWrapper1=newQueryWrapper<>();kltSoftExamineQueryWrapper1.select("server_ip").groupBy("server_ip").eq("平台m",platForm.getPlatform());ListserverIps=kltSoftExamineMapper.selectList(kltSoftExamineQueryWrapper1);JSONObjectjsonServerObject=newJSONObject();AtomicIntegeri=newAtomicInteger();serverIps.forEach(serverIp->{jsonServerObject.put("serverName","licens-server"+i);//2.1i.getAndIncrement();jsonServerObject.put("serverIp",serverIp.getServerIp());//2.2//获取softListJSONArrayjsonSoftListArray=newJSONArray();QueryWrapperkltSoftExamineQueryWrapper2=newQueryWrapper<>();kltSoftExamineQueryWrapper2.select("soft_name").groupBy("soft_name").eq("server_ip",serverIp.getServerIp());列表softNames=kltSoftExamineMapper.selectList(kltSoftExamineQueryWrapper2);JSONObjectjsonSoftObject=newJSONObject();softNames.forEach(softName->{jsonSoftObject.put("softName",softName.getSoftName());//3.1//获取featureListJSONArrayjsonFeatureListArray=newJSONArray();QueryWrapperkltSoftExamineQueryWrapper3=newQueryWrapper<>();kltSoftExamineQueryWrapper3.select("feature_name").groupBy("feature_name").eq("soft_name",softName.getSoftName());列表{JSONObjectjsonFeatureObject=newJSONObject();jsonFeatureObject.put("featureName",featureName.getFeatureName());//4.1jsonFeatureListArray.add(jsonFeatureObject);});jsonSoftObject.put("featureList",jsonFeatureListArray);//3.2jsonSoftListArray.add(jsonSoftObject);});jsonServerObject.put("softList",jsonSoftListArray);//2.3jsonServerListArray.add(jsonServerObject);});//serverList是一个JSONArrayjsonPlatObject.put("serverList",jsonServerListArray);//3jsonArray.add(jsonPlatObject);});返回jsonArray;}上面对数据库的操作是基于这样的思路,即取一个表,然后根据查询的字段返回表中进行查询。为了防止查询到的数据重复,使用了groupby()函数。都是手写的,虽然多层嵌套的方法比较笨。愚蠢,但如此有益!