springboot MultipartFile文件上傳遇到的問題

1.ajax傳過去的參數在controller接受不到

解決:在contoller中增加@RequestParam

例如:saveUploadFile( @RequestParam("file") MultipartFile file,HttpServletRequest request)

2.org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present

將ajax 請求的contextType 改成“multipart/form-data; charset=utf-8”,原來是“text/html; charset=UTF-8”格式都是不對的。還是會出現問題,最後改到 contentType: false,請求不使用contentType

3.org.thymeleaf.exceptions.TemplateInputException: Error resolving template "test/upload", template might not exist or might not be accessible by any of the configured Template Resolvers

解決:是contorller層沒有返回數據,要麼返回String 直接指向頁面,要麼返回數據值輸出

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章