• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring 3 @PathVariable problem with slash

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new to Spring 3. I'm trying to use @PathVariable as follows:



It works well for URLs like /test/someValueHere/test. However when someString needs to have a slash in it like /test/abc/abc/test, Spring doesn't recognize it anymore as matching the pattern. Previously I do it like /test/**/test in Spring 2.5 but this time I need to use PathVariable to easily extract out the someString value.

Anyone can help? Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ronwaldo Cruz wrote:Hi,

I'm new to Spring 3. I'm trying to use @PathVariable as follows:



It works well for URLs like /test/someValueHere/test. However when someString needs to have a slash in it like /test/abc/abc/test, Spring doesn't recognize it anymore as matching the pattern. Previously I do it like /test/**/test in Spring 2.5 but this time I need to use PathVariable to easily extract out the someString value.

Anyone can help? Thanks


Well, to Spring those are two totally different URLs a slash has meaning in a URL. the "**" is just a wildcard the PathVariable isn't a wildcard.

Why would you want someString parameter to be "abc/abc"? Because each PathVariable usually has some kind of meaning and to me "abc" has one meaning and the other "abc" would have a different meaning.

Mark
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Ok. I understand what you mean. abc would be "sort of" a directory structure and then inside it is another abc "directory." But the thing is this is the situation I'm in. I have a url where someString in test/someString/test is a value that can have a slash in it. That is the business requirement. Is there any way of forcing the issue here and extracting someString from the path?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ronwaldo Cruz wrote:Hi,

Ok. I understand what you mean. abc would be "sort of" a directory structure and then inside it is another abc "directory." But the thing is this is the situation I'm in. I have a url where someString in test/someString/test is a value that can have a slash in it. That is the business requirement. Is there any way of forcing the issue here and extracting someString from the path?


The only way around it is to create two methods mapped to the two totally different URL and have one of them call the other



Now you mapped both versions and the someOtherMethod just calls someMethod so the someOtherMethod is just there to map the other URL and get that slash in there.

Hope that helps

Mark
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's not a good idea. How about the parameter has one more slash?

I have a same issue. The parameter exists in many rest API. It's annoying to add one more method seldom used to every rest API.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
qunfeng wang wrote:I think that's not a good idea. How about the parameter has one more slash?

I have a same issue. The parameter exists in many rest API. It's annoying to add one more method seldom used to every rest API.


But in each REST api, each URL is a different resource. Nothing to do with WebPage requests. So another slash would be a different resource. So you would have that mapped to a different method. HATEOAS

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also. Please don't resurrect old threads. This is almost a year old. The poster probably won't see your post anyway, and has already moved on long ago.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic