Springboot通過url訪問本地圖片代碼實(shí)例
1.引入jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
2.創(chuàng)建配置類
package com.common.config;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/** * @BelongsProject: demo * @Author: DanBrown * @CreateTime: 2020-03-28 14:33 * @description: TODO */@Configurationpublic class WebConfig implements WebMvcConfigurer { @Value('${upload.path}') private String uploadPath; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { // /home/file/**為前端URL訪問路徑 后面 file:xxxx為本地磁盤映射 registry.addResourceHandler('/home/file/**').addResourceLocations('file:C:' + uploadPath); }}
3. 訪問
http://localhost:8080/home/file/820123.png
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 前端從瀏覽器的渲染到性能優(yōu)化2. 讀大數(shù)據(jù)量的XML文件的讀取問題3. 解析原生JS getComputedStyle4. css代碼優(yōu)化的12個(gè)技巧5. PHP循環(huán)與分支知識(shí)點(diǎn)梳理6. ASP基礎(chǔ)入門第三篇(ASP腳本基礎(chǔ))7. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁8. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)9. 利用CSS3新特性創(chuàng)建透明邊框三角10. ASP實(shí)現(xiàn)加法驗(yàn)證碼
