无法映射控制器中的 url
我有像 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它应该是:
@RequestMapping(value = "/create", method = RequestMethod.GET)
it should be:
@RequestMapping(value = "/create", method = RequestMethod.GET)
请求映射的要点是将每个方法映射到不同的 url。在你的情况下:
The point of the request-mapping is to map each method to a different url. In your case:
如果您的 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/"})