java如何在JSP中循环存储在Spring HashMap模型中的键和值?
我的Spring控制器中有一个方法:
public ModelAndView testRoCompliance(@RequestParam String regOfficeStr) {
Map<String, Object> results = new HashMap<>();
results.put("inputs", "an input");
results.put("result", "the answer");
ModelAndView modelAndView = new ModelAndView("simpleOutput", results);
return modelAndView;
}
我有一个JSP可以打印变量:
<body>
Inputs: ${inputs}
<br/>
Result: ${result}
</body>
与其显式地列出变量,我如何循环遍历我的results
HashMap的键和值
# 1 楼答案
使用c:forEach标记,然后只引用每个项目的
key
和value
字段这需要更改控制器: