Java 为什么我在尝试访问rest时出现404错误?
当我尝试访问url时,我收到404错误,如:Java 为什么我在尝试访问rest时出现404错误?,java,spring,rest,spring-mvc,Java,Spring,Rest,Spring Mvc,当我尝试访问url时,我收到404错误,如: GET: /test/{id} 注:id是一个字符串,根据用户过滤器的不同而变化 我已经在web.xml中映射了“/test”,但我不知道如何声明一些“我不知道”的值,在本例中是“id” 让我举一个例子: @RequestMapping(value="/test/{id}", method = RequestMethod.GET) public ModelAndView testingId(@PathVariable String id ){
GET: /test/{id}
注:id是一个字符串,根据用户过滤器的不同而变化
我已经在web.xml中映射了“/test”,但我不知道如何声明一些“我不知道”的值,在本例中是“id”
让我举一个例子:
@RequestMapping(value="/test/{id}", method = RequestMethod.GET)
public ModelAndView testingId(@PathVariable String id ){
System.out.println("id");
return new ModelAndView("returns", "returns", id);
}
有什么帮助吗?您使用什么方法来配置web应用程序DispatcherServlet(web.xml或WebApplicationInitializer) 您的请求需要包括servlet上下文、servlet映射和资源映射。假设您的应用程序名为sample.war,并且DispatcherServlet映射到/app/*那么您的请求应该是 获取:/sample/app/test/4
- 您正在返回ModelAndView,您的ViewResolver是什么?默认情况下,它将尝试查找具有该名称的jsp,但找不到它。您想返回jsp还是json对象
- 您的应用程序是否使用SpringBoot,或者您是否使用@AutoScan或配置的控制器映射对其进行了配置
- 放一条调试语句,确保您的请求进入方法,调试到spring方法,您可以看到spring如何解析视图
- Id将是您试图查询的资源的标识符。示例:/users/123456-用户id