Springboot通过url访问本地图片代码实例

网友投稿 405 2023-06-16

Springboot通过url访问本地图片代码实例

Springboot通过url访问本地图片代码实例

1.引入jar包

org.springframework.boot

<artifactId>spring-boot-starter-web

2.创建配置

package com.common.config;

import org.springframework.beans.factory.annotathttp://ion.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

*/

@Configuration

public class WebConfig implements WebMvcConfigurer {

@Value("${upload.path}")

private String uploadPath;

@Override

public void addResourceHandlers(ResourceHandlerRegistry regiszYsHNtry) {

// /home/file/**为前端URL访问路径 后面 file:xxxx为本地磁盘映射

registry.addResourceHandler("/home/file/**").addResourceLocatzYsHNions("file:C:" + uploadPath);

}

}

3. 访问

http://localhost:8080/home/fihttp://le/820123.png

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何用IDEA调试BUG的几种方法
下一篇:SpringBoot通过整合Dubbo解决@Reference注解问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~