Springboot通過(guò)url訪問(wèn)本地圖片代碼實(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訪問(wèn)路徑 后面 file:xxxx為本地磁盤映射 registry.addResourceHandler('/home/file/**').addResourceLocations('file:C:' + uploadPath); }}
3. 訪問(wèn)
http://localhost:8080/home/file/820123.png
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Java如何基于反射機(jī)制獲取不同的類2. Vuex localStorage的具體使用3. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象4. 在IDEA中實(shí)現(xiàn)同時(shí)運(yùn)行2個(gè)相同的java程序5. python+excel接口自動(dòng)化獲取token并作為請(qǐng)求參數(shù)進(jìn)行傳參操作6. asp判斷某個(gè)文件是否存在的函數(shù)7. Docker 制作鏡像Dockerfile和commit操作8. PHP安全-遠(yuǎn)程文件風(fēng)險(xiǎn)9. Android table布局開發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器10. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)

網(wǎng)公網(wǎng)安備