How to make the RequestMapping to handle GET parameters in the url? For example i have this url
localhost:8080/MyApplication/spm/gcNkyLXkwv
how to get the spm value from the above url
How to make the RequestMapping to handle GET parameters in the url? For example i have this url
localhost:8080/MyApplication/spm/gcNkyLXkwv
how to get the spm value from the above url
This can be done using PathVariable. I will just give example how it can be done. You can incorporate in your example
Suppose you want to write a url to fetch some order, you can say
www.mydomain.com/order/123
where 123
is orderId.
So now the url you will use in spring mvc controller would look like
/order/{orderId} Now order id can be declared a path variable
@RequestMapping(value = " /order/{orderId}", method=RequestMethod.GET)
public String getOrder(@PathVariable String orderId){
//fetch order
}
if you use url www.mydomain.com/order/123
, then orderId
variable will be populated by value 123 by spring
Also note that PathVariable differ from requestParam as pathVariable are part of URL. The same url using request param would look like www.mydomain.com/order?orderId=123