当我从邮差打电话时显示不可接受的错误

问题描述 投票:0回答:1
@RestController
@RequestMapping("/Home")
public class HomeController {
    
    private final IHomeService homeService;

    @Autowired
    public HomeController(IHomeService homeService){
        this.homeService = homeService;
    }

    @GetMapping("/hello")
    public @ResponseBody Emp hello() {
        return homeService.getEmp();
    }
}

当我尝试从 Postman 发送请求时,我想将对象作为 JSON 对象发送:

{
    "timestamp": "2024-04-30T11:39:23.093+00:00",
    "status": 406,
    "error": "Not Acceptable",
    "path": "/Home/hello"
}
java json spring-boot spring-mvc
1个回答
0
投票

您需要使用 POST api 传递请求正文并在数据库中创建记录。

    @PostMapping("/hello")
    public @ResponseBody Emp hello( @RequestBody Emp emp ) {
        return homeService.getEmp();
    }

GET API 用于检索现有创建的记录。

有关 HTTP 方法的更多详细信息,您可以参考下面的HTTP-Methods

© www.soinside.com 2019 - 2024. All rights reserved.