Question

How can I call the method below using a http post. Is it necessary to use JSON and @Requestbody. I also don't wont to use spring forms.

I am not seeing any way to accomplish this without a JSON post. How would the html form lok like?

@Requestmapping(value="/post", method=RequestMethod.POST)
public void post(List<MyCustomObject> myList, AnotherCustom object){
    System.out.println("POST")
}

This is how long i come so far. This works bu how to create collection from ahtml from?

Controller

@RequestMapping(value="/post" , method=RequestMethod.POST)
public String post(Person person){
    System.out.println(person);
    return "home";
}

My form

<form method="post" action="/application/post">
    <input name="firstName"> <input name="lastName"> 
    <input type="submit">
</form>
Was it helpful?

Solution

Follow below URL for sample code to pass data to controller(HTML form) and unit test controller.

https://github.com/ffazil/SpringMVC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top