废话不多说直接上代码:
# 代码的controller
@GetMapping(path = "/download/**")
public ResponseEntity downloadFile(HttpServletRequest request) {
final String pattern =
request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString();
final String bestMatchingPattern =
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();
String filePath = new AntPathMatcher().extractPathWithinPattern(bestMatchingPattern, pattern);
Resource resource