<强> 1。引入jar包强>
& lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-web & lt;/dependency>
<强> 2。创建配置类强>
包com.common.config; 进口org.springframework.beans.factory.annotation.Value; 进口org.springframework.context.annotation.Configuration; 进口org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 进口org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/* * * @BelongsProject:演示 * @Author: DanBrown * @CreateTime: 2020-03-28 14:33 * @description:待办事项 */@ configuration 公共类WebConfig实现WebMvcConfigurer { @ value (" $ {upload.path} ") 私人字符串uploadPath; @Override 公共空间addResourceHandlers (ResourceHandlerRegistry注册表){///home/file/* *为前端URL访问路径后面文件:xxxx为本地磁盘映射 registry.addResourceHandler (“/home/文件/* *”)。addResourceLocations(“文件:C:”+ uploadPath); } } >之前<强> 3。访问强>
http://localhost: 8080/home/文件/png
820123.以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Springboot通过url访问本地图片代码实例