I wrote a project where the string is returned the other way around.
@PostMapping(\"/reverse\")
public String reverseList(@RequestBody String string) {
List&
Try to do this. It will make your work easier.
Send a1=10+a2=10+a3=10
instead of a1+a2+a3
in the curl command.
Command :
curl -H "Content-Type: application/json" -d "a1=10+a2=10+a3=10" localhost:8080/hello/reverse
Update the code to this :
@PostMapping("/reverse")
public String reverseList(@RequestBody String str) {
int sum = 0;
String[] variables = str.split("\\+");
for (String variable : variables) {
sum += Integer.parseInt(variable.split("=")[1]);
}
return String.valueOf(sum);
}