@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();
}
}
当我尝试从邮递员发送请求时,我想将对象作为 json 对象发送 { "时间戳": "2024-04-30T11:39:23.093+00:00", “状态”:406, "error": "不可接受", “路径”:“/Home/你好” }
您需要使用 POST api 传递请求正文并在数据库中创建记录。
@PostMapping("/hello")
public @ResponseBody Emp hello( @RequestBody Emp emp ) {
return homeService.getEmp();
}
GET API 用于检索现有创建的记录。
有关 HTTP 方法的更多详细信息,您可以参考下面的HTTP-Methods。