为什么要进行静态资源的映射?
- 将不存放在
resources
/static
中的资源设置访问。 - 设置一个配置类:
addResourceHandler
:访问的路径资源(在网页上)addResourceLocations
:在本地的资源(classpath-->resources
包目录)
package com.mannor.reggie_take_out.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Slf4j
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info("开始进行静态资源的映射.....");
registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
}
}