All Downloads are FREE. Search and download functionalities are using the official Maven repository.

love.keeping.starter.web.config.UploadAutoConfiguration Maven / Gradle / Ivy

The newest version!
package love.keeping.starter.web.config;

import love.keeping.starter.common.utils.StringUtil;
import love.keeping.starter.web.config.properties.UploadProperties;
import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableConfigurationProperties(UploadProperties.class)
public class UploadAutoConfiguration implements WebMvcConfigurer {

  @Autowired
  private UploadProperties properties;

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {

    if (StringUtil.isNotBlank(properties.getUrl()) && StringUtil.isNotBlank(
        properties.getLocation())) {

      String url = properties.getUrl();
      String location = properties.getLocation();

      registry.addResourceHandler(url.endsWith("/") ? url + "**" : url + "/**")
          .addResourceLocations(
              "file:" + (location.endsWith(File.separator) ? location : location + File.separator));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy