Spring Boot 判断请求是否为静态资源
Spring Boot About 489 words方法
ResourceUrlProvider
的getForLookupPath
方法,如果是正常RESTful
的请求会返回为null
,如果是静态资源则会返回对应的URL
。
代码
import org.springframework.web.servlet.resource.ResourceUrlProvider;
@Resource
private ResourceUrlProvider resourceUrlProvider;
HttpServletRequest request = xxx;
String staticResourceUrl = resourceUrlProvider.getForLookupPath(request.getRequestURI());
if (Objects.equals(request.getRequestURI(), staticResourceUrl)) {
log.debug("static resource url: {}", request.getRequestURI());
return;
}
Views: 738 · Posted: 2024-04-02
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...