Getting an array of an object from a web form using the Spring structure

I have a JSP form web page, this form contains several instances of the same Java object. I use the Java Spring Framework to control the "communication" with the controller and view.

My problem is that I would like to get from the view a simple array containing instances of my objects that are currently on the page (probably changed).

When I want a specific type of element, I usually call it in the declaration of the controller method, however for an array (or any collection) this will not work.

so something like:

@RequestMapping
public String edit(...SomeObject[] objectName, ...){
}

will just return me an error, however I can get an array of String, so this works:

@RequestMapping
public String edit(...String[] objectString, ...){
}

, Spring !

+3
2

Spring , String, PropertyEditor .

5 Spring 13 , .

0

, , ; @RequestMapping, , , "command" ( @ModelAttribute)

POJO

public class FooCommand {
    private List<String> myCollection;
    // Getter & Setter
}

@RequestMapping(value = "/foo", method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("fooCommand") FooCommand fooCmd) {
    // do stuff with fooCmd.getMyCollection() 
}

?

+2

Source: https://habr.com/ru/post/1714072/


All Articles