提出
在将SSM项目改为springboot项目时,SSM中的webapp静态资源目录需要去除加入到Boot项目中的resources目录,最近再看Springboot3 雷风阳老师的课,然后就想着使用静态资源缓存策略来解决静态资源映射的问题
首先是我原始ssm项目的目录结构如下:
html和js,css等都放在了webapp下,不方便调试,那就动手修改一下吧。
首先我添加了一个配置类
package com.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
/**
* 静态资源映射
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//本应用
registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
registry.addResourceHandler("/admin/**").addResourceLocations("classpath:/admin/");
}
}
在更改配置对应的目录结构放置方式如下:
这样就可以访问了!