I am trying to learn Spring Boot and working on a simple REST API which I develop a simple calculator.
I have a service class annotated with @Service and it has a simple method
public double calculate(String operation, double num1, double num2) {
...
}
And I am calling this method from the controller like
@GetMapping("/calculate")
public double calculate(@RequestParam(value = "op") String op,
@RequestParam(value = "num1") double num1,
@RequestParam(value = "num2") double num2) {
return calculatorService.calculate(op, num1, num2);
}
I want to validate these parameters(Whether num1 and num2 are numeric and all parameters should be not null). What is the best practice to validate the request parameters for Spring Boot?