Update ConfigurerAdapter.java

main
pveayojnc 4 months ago
parent 50dd029de9
commit 3ea549bac1

@ -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; package com.zsz.config;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -21,26 +6,35 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource; import javax.annotation.Resource;
/** /**
* WebMvcConfigurer * WebMvc
* * Spring MVC
* @author Zheng Jie *
* @date 2018-11-30 * @author
* @date 2018-11-30
*/ */
@Configuration @Configuration // 标识这是一个Spring配置类
//@EnableWebMvc //@EnableWebMvc // 如需完全接管MVC配置可取消注释当前被注释表示保留Spring Boot自动配置
public class ConfigurerAdapter implements WebMvcConfigurer { public class ConfigurerAdapter implements WebMvcConfigurer {
@Resource @Resource // 自动注入系统工具类(按名称装配)
private SystemUtil systemUtil; private SystemUtil systemUtil;
// 文件存储路径前缀常量
public static final String PATH_PREFIX = "upload/"; public static final String PATH_PREFIX = "upload/";
/**
*
* URL
*
* @param registry
*/
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { 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());
} }
}
}
Loading…
Cancel
Save