Java4life
Java4life

Reputation: 109

send Boolean as pathvariable to controller

Is it possible and a good practice to send Boolean as pathvariable to controller in url? I am using spring 3.1 and been trying to send a boolean from Jsp to the controller as @Pathvariable("yesorNo") boolean yesOrNo. But keep getting error as the request is syntactically incorrect. Any insight?

Upvotes: 8

Views: 13782

Answers (1)

Chris Thompson
Chris Thompson

Reputation: 35598

Yes, you can, it would look like

@RequestMapping(value="value/{someVal}")
public void handleBooleanParameter(@PathVariable("someVal")boolean someVal){
   //do something
}

You would then access it with

http://<base url>/value/true

or

http://<base url>/value/false

Upvotes: 9

Related Questions