如何在Spring MVC中将多维数组作为@RequestParam处理? [英] How to handle multidimensional array as @RequestParam in Spring MVC?

查看:79
本文介绍了如何在Spring MVC中将多维数组作为@RequestParam处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上,我有一个发送以下输入的表格:

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>

如何在Spring MVC中以 @RequestParam 处理此问题?

How to handle this in Spring MVC as @RequestParam?

到目前为止,我尝试过

@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");

但没有成功.

推荐答案

您需要将其包装在一个自定义对象中,该对象将保存Map对象.然后,您将不得不更改表单的提交和初始化.

You will need to wrap that in a custom object , which will hold the Map object. 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

更多信息此处

这篇关于如何在Spring MVC中将多维数组作为@RequestParam处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆