Here’s another handy stuff I found on Spring MVC, if you have an unknown number of elements on your form (say a fruit basket), you can bind them into a List with annotation.
Each text input has the same name fruits
:
On your controller’s handler method, you can obtain the list of all fruit names by binding it like this:
(value = "/", method = RequestMethod.POST) public String addFruits(("fruits") Listfruits) { // ... }
The order of fruit names added to the list will be the same as the order of your form text inputs.
Thanks, nice post