list 嵌套list

≡放荡痞女 提交于 2020-02-06 06:00:02

public List<Map<String, Object>> getdaohang() {
  List<Map<String, Object>> listone = new ArrayList<>();
  String sqlone = "SELECT id,name,url FROM column_info WHERE parent ='0' ORDER BY sort asc";
  listone = sqlMapper.selectList(sqlone);
  if (listone.size() > 0) {
    for (int j = 0; j < listone.size(); j++) {
    String sqltwo = "SELECT id,name,url FROM column_info WHERE parent ='" + listone.get(j).get("id")+ "' ORDER BY sort asc";
    List<Map<String, Object>> listtwo = sqlMapper.selectList(sqltwo);
    if (listtwo.size() > 0) {
      for (int i = 0; i < listtwo.size(); i++) {
        String sqlth = "SELECT id,name,url FROM column_info WHERE parent ='" + listtwo.get(i).get("id")+ "' ORDER BY sort asc";
        List<Map<String, Object>> listth = sqlMapper.selectList(sqlth);
        if (listth.size() > 0) {
          listtwo.get(i).put("listth", listth);
         }
       }
      listone.get(j).put("listtwo", listtwo);
      }
    }
  }
  return listone;
 }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!