2016-12-31 6 views
0

문서를 MySQL 데이터베이스에 저장하려고합니다. 내가 컨트롤러multipartFile에서 Blob로 변환하지 못했습니다.

@RequestMapping(value = "/save", method = RequestMethod.POST) 
    public String save(
      @ModelAttribute("document") @Valid Document document, 
      BindingResult bindingResult, 
      @RequestParam("content") MultipartFile file) { 

및 형태 다음 한

는 :

<form th:action="@{/save}" th:object="${document}" method="post" enctype="multipart/form-data"> 

     <h4>Nazwa</h4> 
     <input type="text" th:field="*{name}"/> 
     <td style="color:red" th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></td> 

     <h4>Opis</h4> 
     <input type="text" th:field="*{description}"/> 
     <td style="color:red" th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></td> 

     <h4>zawartosc</h4> 
     <input type="file" th:field="*{content}"/> 
     <td style="color:red" th:if="${#fields.hasErrors('content')}" th:errors="*{content}"></td> 

내가 어떻게이 오류를 수정하는 생각이 없습니다 :

Failed to convert property value of type org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile to required type java.sql.Blob for property content; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile] to required type [java.sql.Blob] for property content: no matching editors or conversion strategy found

답변

0

당신이 보인다 파일 변수를 사용하여 계속 유지하려고합니다.

파일을 올바르게 가져 오는 경우 file.getBytes()을 blob 필드에 설정하면 계속 유지할 수 있습니다.

관련 문제