Springboot通過(guò)url訪問(wèn)本地圖片代碼實(shí)例
1.引入jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
2.創(chuàng)建配置類(lèi)
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為本地磁盤(pán)映射 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. jsp+servlet實(shí)現(xiàn)猜數(shù)字游戲2. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法3. 概述IE和SQL2k開(kāi)發(fā)一個(gè)XML聊天程序4. 推薦一個(gè)好看Table表格的css樣式代碼詳解5. 刪除docker里建立容器的操作方法6. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫(huà)特效7. jsp實(shí)現(xiàn)登錄界面8. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析9. asp批量添加修改刪除操作示例代碼10. jsp實(shí)現(xiàn)簡(jiǎn)單用戶7天內(nèi)免登錄
