java - Spring file upload in a mixed form -
I want to upload a file in my spring 3.0 application (made with cry).
I already have the following unit:
@Antity @ RUJAVABIAN @ RUTHOSTRING @ RUNTTT Public Class Selenimphile {@ManyToOne (TargetIntytti = Showcase.Class) @ Zone Column Private Showcase Showcase; @ Lab @basic (fetch = fetchType.LAZY) private byte [] file; Name of the @notational private string; }
but I'm not sure how to implement it / execute on the controller side. Can I do & lt; Input type = file ... & gt;
Form: input & gt; I can mix spring-form tags independently & lt; with normal tags like
I have seen good in MVC-documentation but still need some help to apply it in my specific case.
Update: I think my question was badly prepared. What I wanted to do is make the spring
I came to know how to do this in the old Spring Documents and how it has been implemented in the new Spring 3.0 MVC. Basically it means that you have to register a PropertyEditor in your controllers @InitBinder method. Afterwards everything will behave as expected (provided you have added multipartolarolor to the context and set the correct form encoding). Here's my sample: @RequestMapping ("/ scriptfile / **") @ Controller Public Class ScriptFileController {// We need special property-editor who knows how to pair data // Request a byte [] @InitBinder Public Zero InitBinder (WebDataBinder Binder) {binder.registerCustomEditor (Byte []. Category, New ByteArmaltpaintFile Editor ()); } @RequestMapping (value = "/ scriptfile", method = RequestMethod.POST) public string (@ Valid ScriptFile scriptfile, binding result result, ModelMap modelMap) {if (scriptfile == empty) remove new invalid bizarre conclusion ("require a scriptfile is" ); If (result.hasErrors ()) {modelMap.addAttribute ("scriptFile", scriptfile); ModelMap.addAttribute ("Shows", ShowCase.findAllShowCases ()); Return "script file / create"; } ScriptFile.persist (); Return "redirect: / scriptfile /" + scriptFile.getId (); }}
Comments
Post a Comment