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)文章:
1. python實(shí)現(xiàn)讀取類別頻數(shù)數(shù)據(jù)畫水平條形圖案例2. python中PyQuery庫用法分享3. python操作數(shù)據(jù)庫獲取結(jié)果之fetchone和fetchall的區(qū)別說明4. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享5. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫特效6. 使用css實(shí)現(xiàn)全兼容tooltip提示框7. JavaScript實(shí)現(xiàn)組件化和模塊化方法詳解8. .NET6打包部署到Windows Service的全過程9. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享10. ASP.NET MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收值
