本篇文章为大家展示了在SpringBoot中使用@ResponseBody实现返回图片功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
首先写一个Controller类,包括一个方法,如下:
package com.example.demo.common; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.io.File; import java.io.FileInputStream; @RestController @RequestMapping(value="/api/v1") public class ImageTest { @GetMapping(value = "/image",produces = MediaType.IMAGE_JPEG_VALUE) @ResponseBody public byte[] test() throws Exception { File file = new File("E:\\ce\\1.jpg"); FileInputStream inputStream = new FileInputStream(file); byte[] bytes = new byte[inputStream.available()]; inputStream.read(bytes, 0, inputStream.available()); return bytes; } }
当前标题:在SpringBoot中使用@ResponseBody实现返回图片功能-创新互联
文章URL:https://www.cdcxhl.com/article0/dppeoo.html
成都网站建设公司_创新互联,为您提供微信公众号、响应式网站、App设计、品牌网站建设、网站导航、定制开发
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联