diff --git a/Java/ReUserVar.java b/Java/ReUserVar.java new file mode 100644 index 0000000000000000000000000000000000000000..cc0025d954a8c1bf69cfd7ae6617eb4d60d47075 --- /dev/null +++ b/Java/ReUserVar.java @@ -0,0 +1,35 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReuseVar { + public static void main(String[] args) { + List> handle = handle(""); + System.out.println(handle); + } + + // 模拟下方法,实际是在 service 中的数据处理方法 + public static List> handle(String arg) { + // ... 相关业务查询(arg 在这部分做筛选用) + + List> result = new ArrayList<>(); + HashMap row = new HashMap<>(); + + // 这里模拟下有3条记录 + int rowsNum = 3; + + // 模拟遍历处理 + for (int i = 0; i < rowsNum; i++) { + // 数据处理(mapKey 取的是数据中的标识) + row.put("xxx", new Object()); + // ... 其他处理 设置的key不固定 + row.put("yyy", new Object()); + row.put("zzz", new Object()); + // ... + result.add(row); + } + + return result; + } +} \ No newline at end of file