【发布时间】:2014-07-17 23:14:24
【问题描述】:
在我的情况下,我有一个带有 Spring Data 的控制器类和 Spring MVC 的验证器,它们使用 Thymeleaf 2.1.1 制作的模板处理表单数据
我使用 Spring Framework 3.2.8 和 Spring Security 3.2.3。
控制器
@RequestMapping(value = "/save", method = {RequestMethod.POST, RequestMethod.GET })
public String save(@RequestParam("curriculumVitae") MultipartFile curriculumVitae, @Valid @ModelAttribute("user") User user, BindingResult result, Model model, Pageable pageable) {
try {
user.setCurriculumVitae(curriculumVitae.getBytes());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
userRepository.save(user);
return "/crudUser";
查看
<form id="myform"
action="#"
th:action="@{${url}+'/save'+'?' + ${_csrf.parameterName} + '=' + ${_csrf.token}}"
th:object="${user}"
th:method="post"
enctype="multipart/form-data">
<div class="col-sm-2 col-lg-2">
<div th:class="form-group" th:classappend="${#fields.hasErrors('curriculumVitae')}? has-error">
<label class="control-label" scope="col"
th:text="#{crudUser.curriculumVitae}">Curriculum Vitae</label>
<input class="form-control input-sm" type="file" th:field="*{curriculumVitae}" name="curriculumVitae" />
</div>
</div>
</form>
我的日志中显示的错误是:
Failed to convert property value of type org.springframework.web.multipart.commons.CommonsMultipartFile to required type byte[] for property curriculumVitae; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.web.multipart.commons.CommonsMultipartFile] to required type [byte] for property curriculumVitae[0]: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [org.springframework.web.multipart.commons.CommonsMultipartFile]
提前感谢谁会帮助我。
【问题讨论】:
-
请发布完整的堆栈跟踪和您的 spring 配置
标签: spring jakarta-ee spring-mvc spring-security thymeleaf