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. 詳解Vue中Axios封裝API接口的思路及方法2. 通過工廠模式返回Spring Bean方法解析3. 關(guān)于Mysql-connector-java驅(qū)動(dòng)版本問題總結(jié)4. JSP實(shí)現(xiàn)客戶信息管理系統(tǒng)5. SpringBoot快速集成jxls-poi(自定義模板,支持本地文件導(dǎo)出,在線文件導(dǎo)出)6. python:刪除離群值操作(每一行為一類數(shù)據(jù))7. python 批量下載bilibili視頻的gui程序8. 使用css實(shí)現(xiàn)全兼容tooltip提示框9. CSS自定義滾動(dòng)條樣式案例詳解10. python中HTMLParser模塊知識(shí)點(diǎn)總結(jié)
