In the Get request method given below I want to check if more than 1 parameters are given in the request.
It is only allowed to use one of the three possible parameters, when more than 1 is given I will throw an error.
@GetMapping()
public List<Offer> getOffers(@RequestParam(required = false) String title,
@RequestParam(required = false) String status,
@RequestParam(required = false) Double bidValue) {
if (title != null) {
return offerRepo.findByQuery("Offer_find_by_title", title);
}
if (status != null) {
if (EnumUtils.isValidEnum(Offer.Auctionstatus.class, status)) {
return offerRepo.findByQuery("Offer_find_by_status", Offer.Auctionstatus.valueOf(status));
}
else{
throw new
ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Status=%s is not a valid auction status ", status));
}
}
if (bidValue != null) {
return offerRepo.findByQuery("Offer_find_by_minBidValue", bidValue);
}
return offerRepo.findAll();}
How can I check if more than 1 RequestParam
is given in the request?
question from:
https://stackoverflow.com/questions/65646821/how-to-check-if-multiple-requestparameters-are-given-in-get-java-spring-boot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…