# codecommunity **Repository Path**: huanghb1208/codecommunity ## Basic Information - **Project Name**: codecommunity - **Description**: .............. - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-23 - **Last Updated**: 2026-03-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README * 配置拦截器 1.实现HandlerInterceptor接口 2.定义一个@configuration注解类,实现WebMvcConfigurer接口,重写addInterceptors方法配置要拦截的路径。 * 加载不了css样式的问题: ```java @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/templates/"); registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); } } ``` 1. addResourceHandlers并不是在springboot默认的访问的资源文件上添加而是会以该方法中添加的路径去替换默认路径。 所以之前默认在classpath:static/路径下能直接访问的,配置了addResourceHandlers就会被覆盖。 2. 检查是否拦截器拦截了静态资源的路径映射 3. 在controller里面直接return一个页面时,如果没添加模板比如themleaf(源码中定义了视图解析) ```java @ConfigurationProperties(prefix = "spring.thymeleaf") public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; } ``` 则需要自己添加视图解析器.