2016-12-31 154 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フィールドに設定して、それを永続化できるはずです。

関連する問題