前言
- 新建一个MyWebAppConfigurer 配置静态资源需要映射的位置、建议把addResourceLocations的路径写在application.yml中、方面以后部署的打包修改配置文件的时候做外部配置文件加载、方面修改。这边为了节约时间就在代码中写了。
package io.renren.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
*
* @author lyy
* 2021.11.21
*/
//springboot 2.x配置
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/image/**").addResourceLocations("file:C:\Users\Administrator\Desktop\11月毕设\");
}
}
复制代码
2.没有加权限控制的话直接通过IP+端口+项目名以及addResourceHandler中的路径就可以访问了、有权限控制的话需要权限放心或放在static静态资源文件夹下。个人用的shiro权限、所以需要放