I would like to have the form object like this:
public class FormData {
private MultipartFile file1;
private MultipartFile file2;
// setters/getters for above fields and other properties
}
and I would like SpringMVC to bind e.g. <input type="file" name="file1">
HTML form field to my form object property. I haven't found any JSP tag for that (like <form:file path="file1" />
or <form:input type="file" path="file1" />
) in spring-form.tld
. Is it possible at all? If not, is this limitation rooted too deep in Spring internals and cannot be easily overcome?
I know how to bind file upload form value to controller method argument (described in documentation):
@RequestMapping(value = {"/"}, method = RequestMethod.POST)
public ModelAndView compare(@ModelAttribute(FORM_BEAN_NAME) FormData formData,
@RequestParam("file1") MultipartFile file1,
@RequestParam("file2") MultipartFile file2,
BindingResult bindingResult) {
but I would be happier if all HTML form elements are bound to one class and method signature does not boost when new upload fields are added.
I did exactly this a couple of years ago. The only difference I can remember is I used CommonsMultipartFile
instead of an interface. What happens if you try this, it throws an exception or simply values don't get bound?
org.springframework.web.multipart.MultipartFile
interface for that which is more generic - dma_k 2012-05-14 09:34