📜  如何使用弹簧在 mongodb 中保存图像 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:37.003000             🧑  作者: Mango

代码示例1
import org.springframework.http.MediaType;

@GetMapping(value = "/file/image/{id}", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE})
@ResponseBody
public byte[] image(@PathVariable String id){
    byte[] data = null;
    UploadFile file = mongoTemplate.findImageById(id, UploadFile.class);
    if(file != null){
        data = file.getContent().getData();
    }
    return data;
}