添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Spring Boot 配置拦截器的时候默认 是放行 静态资源 , 也就是说不需要进行配置

registry.addResourceHandler("/**")
.addResourceLocations("classpath:/resources")
.addResourceLocations("classpath:/static")
.addResourceLocations("classpath:/templates")
.addResourceLocations("classpath:/public");

但是 我发现一个问题 ,同一个目录结构能加载css img 但是不能加载 js 你说这个就奇葩了,

Spring Boot 静态资源能加载css 不能加载js_静态资源

)
.addResourceLocations("classpath:/resources")
.addResourceLocations("classpath:/static/") # 这里加个反斜杠
.addResourceLocations("classpath:/templates")
.addResourceLocations("classpath:/public");

我有单独在拦截器排除了 静态资源 ,发现还是不行, 那肯定资源没有加载进来,  后来 多加了一个反斜杠解决

总结:

我们处理静态资源的时候, 如果是多层目录 一定要 多加一个反斜杠



java 全局异常 java全局异常注解

使用 @ControllerAdvice 或者 @RestControllerAdvice 注解作为统一异常处理的核心。这两个注解都是 Spring MVC 提供的。作用于 控制层 的一种切面通知。 功能:   全局异常处理。   全局数据绑定。   全局数据预处理。【@ControllerAdvice 与 @RestControllerAdvice 区别:】 @RestControlle