Springboot通過圖片路徑形式獲取圖片
一致以來都是用 http://127.0.0.1:8888/getPhoto?imgUrl=1.jpg 的形式獲取數(shù)據(jù),今天突然要 http://127.0.0.1:8888/getPhoto/1.jpg 這樣獲取圖片數(shù)據(jù),竟然有點(diǎn)懵逼了。
直接貼代碼:
@RequestMapping(value = '/getPhoto/{imgUrl:[a-zA-Z0-9_.]+}', produces = MediaType.IMAGE_JPEG_VALUE)@ResponseBodypublic 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;}
演示效果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
