springboot图片路径形式获取图片

Posted 啊基米舍的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot图片路径形式获取图片相关的知识,希望对你有一定的参考价值。

一致以来都是用 http://127.0.0.1:8888/getPhoto?imgUrl=1.jpg 的形式获取数据,今天突然要 http://127.0.0.1:8888/getPhoto/1.jpg 这样获取图片数据,竟然有点懵逼了。

 

直接贴代码:

@RequestMapping(value = "/getPhoto/{imgUrl:[a-zA-Z0-9_.]+}", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public byte[] getPhoto(@PathVariable("imgUrl") String imgUrl) {
    File file = new File("D:/test.jpg");
    FileInputStream inputStream = new FileInputStream(file);
    byte[] bytes = new byte[inputStream.available()];
    inputStream.read(bytes, 0, inputStream.available());
    return bytes;
}

演示效果:

image

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

以上是关于springboot图片路径形式获取图片的主要内容,如果未能解决你的问题,请参考以下文章