简体   繁体   English

为什么我在尝试休息时遇到404错误?

[英]Why i get 404 error trying to acess a rest?

im getting 404 error when i try to visit an url like: 当我尝试访问以下网址时,我收到404错误:

GET: /test/{id}

PS.: id is a string that changes according users filter PS .: id是根据用户过滤器而变化的字符串

I have "/test" already mapped in web.xml, but i dont know how to declare some value that "i dont know", in this case, "id". 我已经在web.xml中映射了“ / test”,但是我不知道如何声明“我不知道”的某些值,在这种情况下为“ id”。

Let me show an example: 让我举一个例子:

@RequestMapping(value="/test/{id}", method = RequestMethod.GET) 
public ModelAndView testingId(@PathVariable String id ){

    System.out.println("id");

    return new ModelAndView("returns", "returns", id);
}

Any Help? 有帮助吗?

What method are you using to configure your web application DispatcherServlet (web.xml or WebApplicationInitializer) 您使用什么方法来配置Web应用程序DispatcherServlet(web.xml或WebApplicationInitializer)

Your request needs to include the servlet context , servlet mapping and resource mapping. 您的请求需要包括servlet上下文,servlet映射和资源映射。 Assuming that your application is called sample.war and your DispatcherServlet is mapped to /app/* then your request should be 假设您的应用程序名为sample.war,并且您的DispatcherServlet映射到/ app / *,则您的请求应为

GET : /sample/app/test/4 GET:/ sample / app / test / 4

  • you are returning ModelAndView, what is you ViewResolver? 您要返回ModelAndView,您是什么ViewResolver? By default it will try to find jsp with that name and it can't find it. 默认情况下,它将尝试查找具有该名称的jsp,但找不到它。 Do you want to return jsp or json object? 是否要返回jsp或json对象?
  • Does your application use SpringBoot or did you configured it with @AutoScan or configured Controller mapping? 您的应用程序使用SpringBoot还是使用@AutoScan或已配置的Controller映射对其进行了配置?
  • Put a debug statement and make sure that your request gets into the method, debug into spring methods and you can see how Spring resolves the view. 放置一条调试语句,并确保您的请求进入方法,调试到Spring方法,然后您可以看到Spring如何解析视图。
  • Id would be identifier of the resource you are trying to query. Id将是您要查询的资源的标识符。 Example: /users/123456 - user id 示例:/ users / 123456-用户ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM