spring - 如何在其方法中访问此端点 @GetMapping("/catalog/**") 的 url?
问题描述
我有以下端点:
@GetMapping("/catalog/**")
public String getCatalog(final Model model){
// code
}
这个端点处理这样的 url:catalog/clothes、catalog/clothes/men、catalog/clothes/women等等。当我输入这样的网址时:
http://localhost:8080/catalog/clothes/women
这个端点被触发。我需要在方法中获取这个 url。我怎样才能做到这一点?
提前致谢。
解决方案
第二个片段看起来不错,它没有被调用的问题似乎在其他代码中,或者共享类/配置代码。
@Controller
public class CatalogController {
private static final Logger logger = LoggerFactory.getLogger(CatalogController.class);
@GetMapping("/catalog/**")
public String getCatalog(final Model model, HttpServletRequest request, HttpServletResponse response){
logger.debug(request.getRequestURL().toString());
logger.debug(request.getQueryString());
logger.debug("Inside catalog");
return null;
}
}
如果您输入的 URL 类似于 - http://localhost:8080/catalog/a/b/c/d?key=value 上面的代码将记录:
- http://localhost:8080/catalog/a/b/c/d(网址)
- 键=值(查询字符串)
http://localhost:8080/catalog/a/b/c/d
推荐阅读
- java - 如何修复 java.util.NoSuchElementException
- python - PYTHON - 检查单元格是否包含来自另一个单元格的字符串
- javascript - 无法通过 AJAX (Cordova) 调用 PHP 文件
- java - 有没有办法简单地监听对象的更改,而不是进行了哪些更改?
- nginx - 如何使用 certbot 将 www 重定向到非 www 用于 HTTPS 和 nginx
- c - VS2017 中的 sprintf 与 wsprintf 的“%.*s”
- javascript - 从 wordpress 站点子文件夹中的非 wordpress 页面获取 wordpress 用户 ID
- c++ - 如何从 C++ 中的字符串返回子字符串?
- node.js - 如何将变量插入到 Firebase 快照中?
- typescript - 如何在 Typescript 中将对象分配给数组