springBoot本地上传照片通过localhost:+端口号访问
-
百度上全是
复制过来会发现
-
WebMvcConfigurerAdapter 已经过期了,spring提供了
-
WebMvcConfigurer
就可以实现了
代码如下
package com.yzt.yztApplication.common;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// /images/**为前端URL访问路径 后面 file:xxxx为本地磁盘映射
registry.addResourceHandler("/images/**").addResourceLocations("file:D:/uploadFiles/");
}
}