[英]How to handle multidimensional array as @RequestParam in Spring MVC?
So, basically, I have a form that sends the following inputs: 因此,基本上,我有一个发送以下输入的表单:
<form>
<input type="text" name="days[monday][start]" value="1">
<input type="text" name="days[monday][end]" value="2">
<input type="text" name="days[tuesday][start]" value="1">
<input type="text" name="days[tuesday][end]" value="2">
</form>
How to handle this in Spring MVC as @RequestParam
? 如何在Spring MVC中将其作为
@RequestParam
?
So far I tried 到目前为止,我尝试了
@RequestParam(value= "days", required = true) Map<String, Object>[] days
......
@RequestParam(value= "days", required = true) Map<String, Map<String, Object>> days
... or even ...
request.getParameter("days");
But without success. 但是没有成功。
You will need to wrap that in a custom object , which will hold the Map object. 您需要将其包装在一个自定义对象中,该对象将保存Map对象。 Then you will have to change the submit and initialization of your form.
然后,您将不得不更改表单的提交和初始化。
public class CustomWrapper{
private Map<String, Object> customMap= new HashMap<String, Object>();
public Map<String, Object> getCustomMap() {
return customMap;
}
public void setCustomMap(Map<String, Object> customMap) {
this.customMap = customMap;
}
}
@RequestParam("days") CustomWrapper days
try something like below: 尝试如下所示:
@RequestMapping(value="/test", method = RequestMethod.POST)
public void method(@RequestParam(value = "param[][]") String[][] paramValues)
{
// rest of your code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.