【发布时间】:2025-11-26 09:50:02
【问题描述】:
我用的是Spring boot,这里是maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
对于网页,我将文件放在 src/main/resources/static 中。那里有我的 html 文件、js 库(angular、jquery)和 css 文件。
我正在尝试使用 Angular 进行 HTTP 请求 POST(我也有一个运行良好的 GET 请求)但我明白了
POST http://localhost:8080/xxxx/12/addEntry 405 (Method Not Allowed)
在响应标头中
HTTP/1.1 405 Method Not Allowed
Server: Apache-Coyote/1.1
X-Application-Context: application
Allow: HEAD, GET
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Wed, 09 Jul 2014 13:04:05 GMT
我意识到在响应中允许没有 POST 方法。
控制器中的方法
@RequestMapping(value = "/xxxx/{uid}/addEntry", method = RequestMethod.POST)
@ResponseBody
public String createEntry(@PathVariable String uid, @RequestBody String form) {
System.out.println(form);
return "index.html";
}
【问题讨论】:
-
你确定 Spring 看到了控制器吗?该控制器的其他方法是否有效?
-
@axtavt 谢谢你的回答。 GET 请求正在运行。
-
如果您尝试删除
@RequestBody String form会怎样? -
@axtavt 谢谢,现在 POST 请求正在运行。您的 cmets 帮助我意识到了这个问题。我没有在 POST 请求中发送 PAYLOAD。
-
那你能回答你自己的问题吗?
标签: spring spring-mvc spring-boot