2016-09-27 78 views
0

我在我的應用程序中使用Springboot和嵌入式服務器(Jetty)。上傳圖片並刷新img標記

我想上傳圖片並重新加載我的html頁面,以在img標籤中顯示新圖片。

Th文件上傳得很好,並保存在我的應用程序的文件夾中。但是當我重新加載我的頁面時,我看不到我的新圖像。

看來我的嵌入式服務器無法看到我的新文件。當我重建我的項目時,我可以看到新文件。

我該怎麼做才能自動刷新我的img標籤不rebuilting我的項目

這裏是我的html頁面

<img th:src="@{/images/scan/}+${signatureScannedImg}" style="margin-bottom: 30px"/> 
      <form th:action="@{/upload-signature-scan}" th:method="post" enctype="multipart/form-data"> 
      <table> 
       <tr><td><input type="file" name="file" /></td></tr> 
       <tr><td><input type="hidden" id="scannedFile" name="scannedFile" value="signature" /></td></tr> 
       <tr><td><input type="hidden" id="idClient" name="idClient" th:value="${clientView.id}" /></td></tr> 
       <tr><td><input type="submit" value="Enregistrer" /></td></tr> 
      </table> 
      </form> 

而且我的控制方法是:

@RequestMapping(value = "/upload-signature-scan", method = RequestMethod.POST) 
    public String handleFileUpload(
           @RequestParam("file") MultipartFile file, 
           @RequestParam("idClient") Long idClient, 
           @RequestParam("scannedFile") String scannedFile, 
           RedirectAttributes redirectAttributes) { 
    Path rootLocation= Paths.get("src/main/resources/static/images/scan"); 
    try { 
     Files.copy(file.getInputStream(), rootLocation.resolve("image.jpg")); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    redirectAttributes.addAttribute("id", idClient); 
    redirectAttributes.addFlashAttribute("id", idClient); 
    redirectAttributes.addFlashAttribute("signatureScannedImg", "image.jpg"); 
    return "redirect:/client/{id}/details"; 
    } 
+0

我們可以看到你的PictureUploadController類嗎? –

+0

是的,我改變了我的帖子 –

回答