简化:resourceconfig
This commit is contained in:
parent
553415d9cd
commit
4ca50fa0c6
|
|
@ -6,6 +6,7 @@ import com.ruoyi.file.service.LocalSysFileServiceImpl;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
|
@ -48,12 +49,12 @@ public class ResourcesConfig implements WebMvcConfigurer
|
||||||
*/
|
*/
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@Override
|
public String getDomain() {
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
return domain;
|
||||||
{
|
}
|
||||||
/** 本地文件上传路径 */
|
|
||||||
registry.addResourceHandler(prefix + "/**")
|
public void setDomain(String domain) {
|
||||||
.addResourceLocations("file:" + path + File.separator);
|
this.domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
|
|
@ -64,14 +65,6 @@ public class ResourcesConfig implements WebMvcConfigurer
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDomain() {
|
|
||||||
return domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDomain(String domain) {
|
|
||||||
this.domain = domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
@ -79,4 +72,25 @@ public class ResourcesConfig implements WebMvcConfigurer
|
||||||
public void setPath(String path) {
|
public void setPath(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||||
|
{
|
||||||
|
/** 本地文件上传路径 */
|
||||||
|
registry.addResourceHandler(prefix + "/**")
|
||||||
|
.addResourceLocations("file:" + path + File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开启跨域
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
// 设置允许跨域的路由
|
||||||
|
registry.addMapping(prefix + "/**")
|
||||||
|
// 设置允许跨域请求的域名
|
||||||
|
.allowedOrigins("*")
|
||||||
|
// 设置允许的方法
|
||||||
|
.allowedMethods("GET");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue