遍历List<Map<String, Object>>
代码
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/dataProcessing")
@Controller
public class dataProcessing {
@RequestMapping(value = "/data.do")
@ResponseBody
public List<Map<String, Object>> data(){
Map map1 = new HashMap<String, Object>();
map1.put("1", "测试1");
map1.put("2", "测试2");
Map map2 = new HashMap<String, Object>();
map2.put("3", "测试3");
map2.put("4", "测试4");
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
list.add(map1);
list.add(map2);
for (Map<String, Object> map : list)
{
for (String mapKey : map.keySet())
{
System.out.println(mapKey + " : " + map.get(mapKey));
}
}
return list;
}
}
结果