//Repository
List<Person> findByEyeColorAndAgeLessThan(String eyeColor, Integer age);
//Controller
@GetMapping("/people/search")
public List<Person> searchPeople(
@RequestParam(name = "eyeColor", required = false) String eyeColor,
@RequestParam(name = "maxAge", required = false) Integer maxAge
) {
if (eyeColor != null && maxAge != null) {
return this.personRepository.findByEyeColorAndAgeLessThan(eyeColor, maxAge);
} else if (eyeColor != null) {
return this.personRepository.findByEyeColor(eyeColor);
} else if (maxAge != null) {
return this.personRepository.findByAgeLessThan(maxAge);
} else {
return new ArrayList<>();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter