可以根据@requestparam的值为请求体提供不同的验证器吗?

wvmv3b1j  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(140)

是的,我已经看过这个了。但我的情况与此不同。在那里,场景中是否有请求参数。但是在我的例子中,我想根据@requestparam的值对@requestbody进行不同的验证。这是可以实现的吗?

@PostMapping("/supplier")
@ApiOperation(value = "Get local attributes of a supplier(s)", notes = "Returns the sms attributes of supplier", response = LocalDTO.class)  
public @ResponseBody
ResponseEntity<ResponseDTO> getSmsForShippingPoint(
        @ApiParam(value = "Search By", required = true) @RequestParam(name = "searchBy") String searchBy,
        @ApiParam(value = "Suvc, Suffix, Site and SmsVendor", required = true) @RequestBody @Valid RequestSmsDTO requestSmsDTO) throws ValidationException {
    if(searchBy.equals("shipping-point")){
        ResponseDTO smsResponseDTO = supplierService.findSmsByShippingPoint(requestSmsDTO);
        return ResponseEntity.status(HttpStatus.OK)
                .body(smsResponseDTO);
    }
    return null;
}

所以基于 searchBy 我需要对requestbody执行不同的验证。就我而言 RequestSmsDTO 对象

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题