问题遇到的现象和发生背景
需求:前台页面上传入一个文件和一段文字,传给后端。
问题相关代码,请勿粘贴截图
new Vue({
el: '#app',
data: {
formJson: {"widgetList":
[
{"type":"file-upload","icon":"file-upload-field","formItemFlag":true,"options":{
"name":"fileexcel","label":"上传excel","labelWidth":null,"labelHidden":false,"disabled":false,"hidden":false,"required":false,"requiredHint":"","customRule":"","customRuleHint":"","uploadURL":"","uploadTip":"","withCredentials":false,"multipleSelect":false,"showFileList":true,"limit":3,"fileMaxSize":5,"fileTypes":["doc","docx","xls","xlsx"],"customClass":[],"labelIconClass":null,"labelIconPosition":"rear","labelTooltip":null,"onCreated":"","onMounted":"","onBeforeUpload":"","onUploadSuccess":"","onUploadError":"","onValidate":""},"id":"fileexcel"}
,{"type":"textarea","icon":"textarea-field","formItemFlag":true,"options":{
"name":"DingText","label":"钉钉文本","labelAlign":"label-center-align","rows":20,"defaultValue":"","placeholder":"","columnWidth":"200px","size":"","labelWidth":null,"labelHidden":false,"readonly":false,"disabled":false,"hidden":false,"required":false,"validation":"","validationHint":"","customClass":"","labelIconClass":null,"labelIconPosition":"rear","labelTooltip":null,"minLength":null,"maxLength":null,"showWordLimit":false,"onCreated":"","onMounted":"","onInput":"","onChange":"","onFocus":"","onBlur":"","onValidate":""},"id":"DingText"}],"formConfig":{"modelName":"formData","refName":"vForm","rulesName":"rules","labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-center-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":""}},
formData: {},
optionData: {}
},
methods: {
submitForm: function() {
this.$refs.vFormRef.getFormData().then( function(formData) {
alert( JSON.stringify(formData))
axios({
headers:{
'Content-Type':'multipart/form-data;boundary=--------------------------383701905023712046165926'
},
method: 'post',
url:"/DingTalk",
data: formData
})
}).catch( function(error) {
// Form Validation Failed
alert(error)
})
}
}
});
@RequestMapping("/DingTalk")
public void getList(HttpServletResponse response,@RequestParam(value = "fileexcel",required = false) MultipartFile file
,@RequestParam(value = "DingText",required = false) String DingText) throws IOException {
}
运行结果及报错内容
·
java.lang.NullPointerException: null
我的解答思路和尝试过的方法
如果要同时传文件+参数,需要包装成formdata
我想要达到的结果
后台能收到文件和参数