如何使用把手中没有路径的图像

时间:2019-11-27 05:59:44

标签: java spring handlebars.js

我想将图像列表传递到“车把”视图中。

ArrayList<ImageIcon> images = new ArrayList<>();
for(Photos p : photos){
    ByteArrayInputStream bis = new ByteArrayInputStream(p.getImage());
    BufferedImage bim = ImageIO.read(bis);
    images.add(new ImageIcon(bim));
}

model.addAttribute("photos", images);

通过调试,我确定此arrayList中有ImageIcon对象。 然后,如何在这样的把手中使用此数组。

{{#each photos as |photo|}}
    <img src={{photo}}>
{{/each}}

我想使用没有文件路径的图像。

1 个答案:

答案 0 :(得分:0)

@GetMapping("/displayImage")
public void displayImage(@RequestParam("email")String email, HttpServletResponse response) throws IOException {
    List<Photos> list = photoService.showImages(email);

    byte[] binaryImage = list.get(0).getImage();
    response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
    response.getOutputStream().write(binaryImage);
    response.getOutputStream().close();
}

<img src="/displayImage/?email={{userInfo.email}}"/>