无法映射控制器中的 url

发布于 2025-01-08 06:44:26 字数 381 浏览 0 评论 0原文

我有像 http://localhost:8080/api/create/ 这样的请求网址,并且控制器有下面的代码

@RequestMapping(value = "/", method = RequestMethod.GET)
    public ResponseEntity<String> getApiResponse(HttpServletRequest request)
            throws Exception {}

控件如何来到这个方法?我在春天有任何方法可以做到这一点,因为我希望请求映射 url 仅是“/”

I have request url like http://localhost:8080/api/create/ ,and the controller has the following code

@RequestMapping(value = "/", method = RequestMethod.GET)
    public ResponseEntity<String> getApiResponse(HttpServletRequest request)
            throws Exception {}

How will the control comes to this method ? I thers any way in spring to do this as i want the request Mapping url to be '/' only

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热情消退 2025-01-15 06:44:26

它应该是:

@RequestMapping(value = "/create", method = RequestMethod.GET)

it should be:

@RequestMapping(value = "/create", method = RequestMethod.GET)

記憶穿過時間隧道 2025-01-15 06:44:26

请求映射的要点是将每个方法映射到不同的 url。在你的情况下:

@RequestMapping(value="/api/create")

The point of the request-mapping is to map each method to a different url. In your case:

@RequestMapping(value="/api/create")
ぽ尐不点ル 2025-01-15 06:44:26

如果您的 Web 应用程序是应用程序服务器上的默认 Web 应用程序,即您不必在 URL 中提及应用程序本身的路径,您必须说

@RequestMapping(value = "/*", method = RequestMethod.获取)

@RequestMapping(value = "/api/create/", method = RequestMethod.GET)

或在类上放置 @RequestMapping 注解:
@RequestMapping(value = "/api/", method = RequestMethod.GET)
然后用注释标记 getApiResponse 方法
@RequestMapping(value = "/create/", method = RequestMethod.GET)

您还可以在一个 @RequestMapping 注解中提及多个 URL:

@RequestMapping(value = {"/api/", "/api", "/api/*", "/api/create/"})

If your web application is a default web application on your application server, i.e. you do no have to mention the path to application itself in your URL you have to say

@RequestMapping(value = "/*", method = RequestMethod.GET)
or

@RequestMapping(value = "/api/create/", method = RequestMethod.GET)

or put @RequestMapping annotation on class:
@RequestMapping(value = "/api/", method = RequestMethod.GET)
and then mark getApiResponse method with annotation
@RequestMapping(value = "/create/", method = RequestMethod.GET)

You can also mention several URLs into one @RequestMapping annotation:

@RequestMapping(value = {"/api/", "/api", "/api/*", "/api/create/"})

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文