Spring 4:按ResponseEntity或其他方式返回对象列表?

时间:2017-04-09 09:19:57

标签: java spring response multipartform-data

-->

我需要根据ResponseEntity返回一个对象列表。我知道,我目前只是列表中的最后一个对象,但我需要一个完整的列表。想法?

@RequestMapping(path = "findAllPhotosByPhotoAlbumTitle", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> findAllPhotosByPhotoAlbumTitle(@PathVariable(value = "albumTitle") String albumTitle) throws IOException {

final List<Photo> allPhotosByPhotoAlbumTitle = photoService.findAllPhotosByPhotoAlbumTitle(albumTitle);

    ResponseEntity<InputStreamResource> body = null;

    for (Photo photo : allPhotosByPhotoAlbumTitle) {
        body = ResponseEntity.ok()
                .contentLength(photo.getMultipartFile().getSize())
                .contentType(MediaType.parseMediaType(photo.getMultipartFile().getContentType()))
                .body(new InputStreamResource(photo.getMultipartFile().getInputStream()));
    }
    return body;
}

0 个答案:

没有答案
相关问题
最新问题