小编did*_*dxb的帖子

Spring Boot:不支持请求方法“POST”

我正在研究 spring boot 并尝试一个简单的 Rest Controller。我有两种使用 HTTP GET 的方法,它们工作正常。但是,当我执行 HTTP POST 时,它不工作,显示 :: 不支持请求方法“POST”

我的控制器代码如下:-

enter code here

package com.example.web.api;
import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
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;

import com.example.model.Greeting;
@RestController
public class GreetingController {

    private static BigInteger nextId;
    private static Map<BigInteger, Greeting> greetingMap;

    private static Greeting save(Greeting greeting){
        if (greetingMap==null){
            greetingMap = new HashMap<BigInteger, Greeting>();
            nextId = BigInteger.ONE;
        }
        greeting.setId(nextId);
        nextId=nextId.add(BigInteger.ONE);
        greetingMap.put(greeting.getId(), greeting); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

spring ×1

spring-mvc ×1