如何获取JavaSpring框架中modelAndView.getModel()返回的spring控制器自身内部modelMap对象中的所有键值对

如何获取JavaSpring框架中modelAndView.getModel()返回的spring控制器自身内部modelMap对象中的所有键值对,java,spring,modelandview,Java,Spring,Modelandview,Map modelMap=modelAndView.getModel() 我想检索modelMap对象中的所有键,以便访问每个值,这些值可以分配给在控制器类本身中创建的变量/对象 ModelMap的通用类型固定在Map 因此,您可以像在HashMap中那样迭代映射的键,您可以使用keyset()或entryset()来 for(Map.Entry:Map.entrySet()){ System.out.println(“Key=“+entry.getKey()+”,Value=“+entry.g

Map modelMap=modelAndView.getModel()


我想检索modelMap对象中的所有键,以便访问每个值,这些值可以分配给在控制器类本身中创建的变量/对象

ModelMap的通用类型固定在
Map

因此,您可以像在
HashMap
中那样迭代映射的键,您可以使用keyset()或entryset()来

for(Map.Entry:Map.entrySet()){
System.out.println(“Key=“+entry.getKey()+”,Value=“+entry.getValue());
}

*ModelMap子类
LinkedHashMap
,它依次扩展
HashMap

ModelMap的通用类型固定在
Map

因此,您可以像在
HashMap
中那样迭代映射的键,您可以使用keyset()或entryset()来

for(Map.Entry:Map.entrySet()){
System.out.println(“Key=“+entry.getKey()+”,Value=“+entry.getValue());
}

*

modelAndView.getModel()返回的Map的运行时类是org.springframework.ui.ModelMap。该类扩展LinkedHashMap而不更改keyset()或entryset()方法。只需使用keyset()或entryset()

modelAndView.getModel()返回的Map的运行时类是org.springframework.ui.ModelMap。此类在不更改keyset()或entryset()方法的情况下扩展LinkedHashMap。只需使用keyset()或entryset()

您已经有了一个映射。因此,您需要询问如何迭代映射的键。您可以使用keyset()或entryset()您已经有一个映射。因此,您需要询问如何遍历映射的键。您可以使用keyset()或entryset()
for (Map.Entry<String, Object> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}