springboot 请求url path提取

@PostMapping(value = "/abc/{p1}/**")
    public Result addFilePermission(@PathVariable(value = "p1") String p1) {
        getExtractPath(request);
   
		return null;
    }
	
	public static String getExtractPath(HttpServletRequest request) {
        //用于获取请求全路径: /demo/put/test/dy_only/test.jpg
        String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        //用户获取匹配到controller的路径:/demo/{dir}/**
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        //使用 AntPathMatcher 匹配所需要的URL : test/dy_only/test.jpg
        return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
    }

你可能感兴趣的:(springboot,servlet,java,spring)