我的 Controller 中有方法:
@GetMapping("/photos")
public ResponseEntity<?> getPhotos(){
List<Photo> photoList = photoService.findAll();
return new ResponseEntity<>(photoList, HttpStatus.OK);
}
它从数据库返回数组:
[{"id": 1,"name": "photo1.jpg","file": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wC...(byte[])"},{...},. ..]
我知道一个文件是这样完成的:
.then(response => {
response.blob().then(blob => {
let url= window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
});
});
但是如何处理数组呢?
最佳答案
您可以使用response.json()代替。
.then(response => {
response.json().then(responseJSON => {
// responseJson should be an array that you can iterate on and manipulate individual objects and parse relevant keys.
});
});
关于java - 如何在react中从服务器获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60939801/