0

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

Akhila k.p
  • 31
  • 1
  • 3
  • Possible duplicate of [With Spring 3.0, can I make an optional path variable?](https://stackoverflow.com/questions/4904092/with-spring-3-0-can-i-make-an-optional-path-variable) – georgeawg Dec 26 '17 at 17:30

1 Answers1

4

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

Shoaib Chikate
  • 8,665
  • 12
  • 47
  • 70
  • Hi, its working perfectly.Thank you for your valuable suggestion. But some issues occurred while populating the result view.The JavaScript file and all other css files are not taken.The path for the JavaScript and css files are shown as networkError: 404 Not Found - localhost:8080/MyApplication/spm/css/style.css". The original path is MyApplication/css/style.css .How to fix this issue. – Akhila k.p Dec 15 '14 at 05:39
  • Are you running application using IDE? – Shoaib Chikate Dec 15 '14 at 06:13
  • Yes using eclipse with spring MVC – Akhila k.p Dec 15 '14 at 06:51
  • I had many times the problem, didn't find solution for that. Hence I m running all the things manually rather than running in IDE. You can raise new issue for that. – Shoaib Chikate Dec 15 '14 at 07:16
  • http://stackoverflow.com/questions/11952212/spring-3-1-javascript-file-not-found-404-error This may help you. – Shoaib Chikate Dec 15 '14 at 07:17
  • And this too http://stackoverflow.com/questions/18373165/spring-mvcresources-tag-and-404-error – Shoaib Chikate Dec 15 '14 at 07:19