What is the difference between @RequestParam
and @PathVariable
while handling special characters?
+
was accepted by @Re
@RequestParam is use for query parameter(static values) like: http://localhost:8080/calculation/pow?base=2&ext=4
@PathVariable is use for dynamic values like : http://localhost:8080/calculation/sqrt/8
@RequestMapping(value="/pow", method=RequestMethod.GET)
public int pow(@RequestParam(value="base") int base1, @RequestParam(value="ext") int ext1){
int pow = (int) Math.pow(base1, ext1);
return pow;
}
@RequestMapping("/sqrt/{num}")
public double sqrt(@PathVariable(value="num") int num1){
double sqrtnum=Math.sqrt(num1);
return sqrtnum;
}