-1
我這是寫在春季4.1休息控制器,請參考下面的代碼如何使用休息呼叫顯示圖像前端?
@RequestMapping(value = "/image", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> downloadUserAvatarImage() {
GridFSDBFile gridFsFile = App.getImageResponse();
return ResponseEntity.ok()
.contentLength(gridFsFile.getLength())
.contentType(MediaType.parseMediaType(gridFsFile.getContentType()))
.body(new InputStreamResource(gridFsFile.getInputStream()));
}
我現在的問題是,我有HTML塊當我加載 http://host.com/title 標題HTML頁面的下面貼
頁面<html>
<body>
<h1>Host.com some title</h1>
<p>Some content</p>
<div id='loadImage'></div>
...
some content
...
</body>
</html>
我想打電話給我休息控制器加載在DIV由ID loadImage
提到的圖像說http://www.host.com/getMyImage
我該怎麼做?