web项目处理图片上传

package com.bootdo.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
   @Autowired
   BootdoConfig bootdoConfig;
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/files/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath());
   }

}

addResourceHandler("/files/**")---映射的虚拟路径

addResourceLocations("file:///"+bootdoConfig.getUploadPath())---指定服务器中分绝对路径(可以去配置)

你可能感兴趣的:(web项目处理图片上传)