Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]报错的问题所在
时间: 2023-12-06 19:36:36 浏览: 175
这个错误通常是由于请求方法不匹配而导致的。在你的代码中,你的@RequestMapping注解指定了一个POST请求,但是你的请求实际上是一个GET请求。因此,你需要将你的请求方法更改为POST或将@RequestMapping注解更改为@GetMapping或@RequestMapping(method = RequestMethod.GET)。
以下是两种解决方法的示例代码:
1. 将请求方法更改为POST
```java
@RequestMapping(value = "/student/{name}/{age}", method = RequestMethod.POST)
public String creatStudent(@PathVariable("name") String name, @PathVariable("age") Integer age){
return "创建资源student"+name+"age="+age;
}
```
2. 将@RequestMapping注解更改为@GetMapping或@RequestMapping(method = RequestMethod.GET)
```java
@GetMapping(value = "/student/{name}/{age}")
public String creatStudent(@PathVariable("name") String name, @PathVariable("age") Integer age){
return "创建资源student"+name+"age="+age;
}
```
阅读全文