我想创建两个rest端点,但它们都具有相同的uri。
/supplier?searchBy=shipping-point
/supplier?searchBy=price-point
首先,我实现了一个端点,如下所示。
@PostMapping("/supplier")
@ApiOperation(value = "Get local attributes of a supplier(s)", notes = "Returns the sms attributes of supplier", response = LocalDTO.class)
@ApiResponses(value = {
@ApiResponse(code = org.apache.http.HttpStatus.SC_BAD_REQUEST, message = "Request validation failed."),
@ApiResponse(code = org.apache.http.HttpStatus.SC_UNAUTHORIZED, message = "Not authorized."),
@ApiResponse(code = org.apache.http.HttpStatus.SC_FORBIDDEN, message = "Not authorized."),
@ApiResponse(code = org.apache.http.HttpStatus.SC_NOT_FOUND, message = "Data not found."),
})
public @ResponseBody
ResponseEntity<ResponseDTO> getSmsForPricePoint(
@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("price-point")){
ResponseDTO smsResponseDTO = supplierService.findSmsByPriceVendor(requestSmsDTO);
return ResponseEntity.status(HttpStatus.OK)
.body(smsResponseDTO);
}
return null;
}
而不是通过创建 if
声明 searchBy.equals()
有没有更好的办法。如果我可以为其他端点使用不同的requestbody dto,那就太好了。
这里我最终需要的是使用不同的requestbody对象调用不同的服务层方法。
暂无答案!
目前还没有任何答案,快来回答吧!