jsp表单中有文件,springMVC不能自动封装成对象
Field error in object 'student' on field 'bikePicture': rejected value [org.springframework.web.multipart.commons.CommonsMultipartFile@6d233e01]; codes [typeMismatch.student.bikePicture,typeMismatch.bikePicture,typeMismatch.java.lang.String,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [student.bikePicture,bikePicture]; arguments []; default message [bikePicture]]; default message [Failed to convert property value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'java.lang.String' for property 'bikePicture'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.commons.CommonsMultipartFile' to required type 'java.lang.String' for property 'bikePicture': no matching editors or conversion strategy found]]
请问应该怎么解决呢
Form表单怎么写的
这个问题是你表单提交的时封装的参数和接口参数对不上导致的,解决:
1.最简单清晰的方式你可以把文件上传这一部分单独作为一个接口实现。
2.就是把表单提交的参数和上传的文件对象单独封装成一个对象,对应后台接口的参数,可以参考:[https://developer.mozilla.org/zh-CN/docs/Web/API/FormData/Using_FormData_Objects]