|
|
|
@ -1,18 +1,3 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019-2020 Zheng Jie
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.zsz.config;
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
@ -21,26 +6,35 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WebMvcConfigurer
|
|
|
|
|
* WebMvc配置类
|
|
|
|
|
* 功能:自定义Spring MVC配置,主要用于静态资源映射
|
|
|
|
|
*
|
|
|
|
|
* @author Zheng Jie
|
|
|
|
|
* @date 2018-11-30
|
|
|
|
|
* @author 郑杰
|
|
|
|
|
* @date 2018-11-30 创建日期
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
//@EnableWebMvc
|
|
|
|
|
@Configuration // 标识这是一个Spring配置类
|
|
|
|
|
//@EnableWebMvc // 如需完全接管MVC配置可取消注释(当前被注释表示保留Spring Boot自动配置)
|
|
|
|
|
public class ConfigurerAdapter implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
@Resource // 自动注入系统工具类(按名称装配)
|
|
|
|
|
private SystemUtil systemUtil;
|
|
|
|
|
|
|
|
|
|
// 文件存储路径前缀常量
|
|
|
|
|
public static final String PATH_PREFIX = "upload/";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 配置静态资源映射
|
|
|
|
|
* 作用:将物理磁盘中的上传文件目录映射为虚拟URL路径
|
|
|
|
|
*
|
|
|
|
|
* @param registry 资源处理器注册器
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
|
registry.addResourceHandler("/" + PATH_PREFIX + "**").addResourceLocations("file:" + systemUtil.getFilePrefix());
|
|
|
|
|
|
|
|
|
|
// 添加资源处理规则:
|
|
|
|
|
// 1. 当访问URL以"/upload/"开头时
|
|
|
|
|
// 2. 将请求映射到systemUtil.getFilePrefix()返回的本地文件系统路径
|
|
|
|
|
registry.addResourceHandler("/" + PATH_PREFIX + "**")
|
|
|
|
|
.addResourceLocations("file:" + systemUtil.getFilePrefix());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|