Spring Boot 判断请求是否为静态资源

Spring Boot About 489 words

方法

ResourceUrlProvidergetForLookupPath方法,如果是正常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: 984 · Posted: 2024-04-02

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh