2017-10-21 167 views
0

我正在开发SpringBoot应用程序。对于POST终点,没有要传递的请求正文。我的服务工作正常。但是,当我在请求的主体中传递一些值时,它也起作用。 如果在请求的主体中传递了某些内容,并且理想情况下该请求仍为空,我该如何验证并返回一个不良请求?验证空请求

*@RequestMapping(value = "/sample/customers", method = POST) 
public Customer session() { 
    return customerService.getCustomer(); 
}* 
+0

为什么在没有body的情况下使用POST?为什么不能获得? – raiyan

+0

也许你可以使用'@Null String body'作为参数 –

回答

0

你不应该使用POST进行数据检索。

您需要2种方法。下面是保存的示例代码:

@ResponseStatus(value = HttpStatus.CREATED) 
@RequestMapping(value = "/sample/customers", method = POST) 
public Customer save(@RequestBody CustomerRequestDto customerRequestDto) { 
    return customerService.save(customerRequestDto); 
}