我有这个简单的代码:
import com.example.civicsenseapp.Model.Segnalazione;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ControlApp
{
@RequestMapping(method = RequestMethod.POST, value="/creaSegnalazione")
public void segnalazione(@RequestBody Segnalazione segnalazione)
{
System.out.println(segnalazione.getCognome());
}
}
我使用Spring Initializr和Thymeleaf创建了项目。我不知道为什么,但是当执行POST请求时,此确切的代码(无错误运行)给我404错误,但是如果我打开昨天用 same 代码创建的另一个项目,则它可以工作完美。
这是怎么回事?
答案 0 :(得分:0)
您必须在此周围添加了一些安全性或输入了错误的URL。如果您要调用GET而不是POST,则会得到405而不是404。因此,很可能是您尝试使用的网址错误。
答案 1 :(得分:0)
您在Spring中设置了基本URI吗?可以将其设置为在路径之前使用“ / api /”之类的名称,而不是使用默认的URI“ /”。您可以在Spring的配置/属性中轻松地进行检查。
答案 2 :(得分:0)
依赖性问题,反正谢谢