我做了一个简单的静态网站,有一些CSS
和JS
:
如果我使用Spring Boot运行它,一切都运行良好,即使JS工作。
现在,我想添加一个简单的POST端点:
@RestController
public class Generator {
@RequestMapping(name = "/generator", method = RequestMethod.POST)
public String payload(final GeneratorPayload payload) {
System.out.println("This is your payload: " + payload.getFirstName());
return "testresp";
}
}
当访问主页面时我抛出org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
(我甚至没有调用该端点),显示错误。
如果我删除内部映射("/generator")
,一切正常。
这就像他重写了默认方法并将其应用于索引?这里发生了什么?
这里有一个错误:
@RequestMapping(name = "/generator", method = RequestMethod.POST)
我已经指定了name
,而不是value
,并且映射被附加到"/"
。
正确的版本:
@RequestMapping(value = "/generator", method = RequestMethod.POST)