0

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?

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.

2
  • can you please share how are you sending this array data from the form Commented Dec 11, 2016 at 1:44
  • I just added a sample HTML Commented Dec 12, 2016 at 11:33

2 Answers 2

1

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

More info here

Sign up to request clarification or add additional context in comments.

Comments

1

try something like below:

@RequestMapping(value="/test", method = RequestMethod.POST)
public void method(@RequestParam(value = "param[][]") String[][] paramValues)
{
    // rest of your code
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.