静态网站不希望使用简单的POST端点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了静态网站不希望使用简单的POST端点相关的知识,希望对你有一定的参考价值。

我做了一个简单的静态网站,有一些CSSJS

enter image description here

如果我使用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)

以上是关于静态网站不希望使用简单的POST端点的主要内容,如果未能解决你的问题,请参考以下文章