हम एक ऐसे फॉर्म के साथ प्रोफाइल पेज बना रहे हैं जिस पर वैकल्पिक रूप से प्रोफाइल चित्र है। हम प्रपत्र स्प्रिंग 3.2वैकल्पिक फ़ाइल के साथ वसंत अपलोड फॉर्म वैकल्पिक
यहाँ का उपयोग कर रहे है: -:
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String onEditPost(@PathVariable long id, @Valid @ModelAttribute(MemberAjaxEditModel.KEY) MemberAjaxEditModel model, BindingResult result) throws ServiceRecoverableException {
....
}
यहाँ मॉडल
public class MemberAjaxEditModel {
...
private CommonsMultipartFile fileData;
...
}
है यह ठीक काम करता है -
<form:form id="editMember" modelAttribute="memberAjaxEditModel"
method="POST" class="form-horizontal" enctype="multipart/form-data" >
...
<form:input path="fileData" type="file"/>
...
</form>
यहाँ नियंत्रक विधि है अगर फ़ाइल पर फ़ाइल सबमिट की गई है, लेकिन फ़ाइल के बिना फ़ॉर्म सबमिट किए जाने पर बाध्यकारी रीसेट चर में त्रुटियां हैं।
Field error in object 'memberAjaxEditModel' on field 'fileData': rejected value []; codes [typeMismatch.memberAjaxEditModel.fileData,typeMismatch.fileData,typeMismatch.org.springframework.web.multipart.commons.CommonsMultipartFile,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [memberAjaxEditModel.fileData,fileData]; arguments []; default message [fileData]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile' for property 'fileData'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.commons.CommonsMultipartFile] for property 'fileData': no matching editors or conversion strategy found]
धन्यवाद @ एश, मुझे एक ही समस्या का सामना करना पड़ रहा था .. यह वास्तव में मेरी मदद करता था .. बस मैंने arr.splice (fileDataIndex, 1) का उपयोग किया; arr.remove (fileDataIndex) के बजाय; – Saurabh
यह मुझे भी फॉर्म बनाता है लेकिन जब मैं सबमिट करने से पहले विकल्प में अपनी विधि का उपयोग करता हूं, तो वेब पेज को प्रतिक्रिया की सामग्री (मैं AJAX व्यवहार खो देता हूं) के साथ पुनः लोड किया जाता है ... – Labe
मुझे वास्तव में पता नहीं है कि क्यों सौरभ संशोधन का उपयोग करके, मेरी समस्या चली गई है धन्यवाद – Labe