in the below example, i am using POST and GET methods. post is to initialize a varibale and GET is to get this varibale. I use Postman to make the requests.
i am receiving an error
@RequestBody(value = "val") //cant resolve method value
please let me know how to fix the belwo error so i can use post method for initialization and get methdo to retrieve the value
Controller1
@Controller
@RequestMapping("/call1")
public class Call1 {
public String str = "inti";
@RequestMapping(value = "/intiparam1", method = RequestMethod.POST)
public void intiParam1(@RequestBody(value = "val") String val) {
this.str = val;
}
@RequestMapping(value = "/getparam1", method = RequestMethod.GET)
public String getParam1() {
return this.str;
}
}
Create a class Variable and use other code in controller.
class Variable {
String data= 'val';
}
@RequestMapping(value = "/intiparam1", method = RequestMethod.POST)
public void intiParam1(@RequestBody Variable val) {
this.str = val.data;
}
When making a request pass json as {"data":"12345"}
and then use @RequestBody Variable v in code instead of String as it will serve your purpose of default value and will make the code extensible as you can add different properties to the existing variable in future if needed.