@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"
}
您需要使用 POST api 传递请求正文并在数据库中创建记录。
@PostMapping("/hello")
public @ResponseBody Emp hello( @RequestBody Emp emp ) {
return homeService.getEmp();
}
GET API 用于检索现有创建的记录。
有关 HTTP 方法的更多详细信息,您可以参考下面的HTTP-Methods。