Reputation: 9813
Designing my RESTful API, I would like use following URI
http://[HOST]/[PLANET]/[LAT];[LONG]
e.g.
http://myserver/earth/50.2;29.1
What is the appropiate annotation of a such a method in Spring MVC? Is this the following one ok?
@RequestMapping(value = "/{planet}/{lat};{long}", method = RequestMethod.GET)
public String showInfoAboutCoords(
@PathVariable final String planet,
@PathVariable final String lat,
@PathVariable final String long,
final HttpServletResponse response) {
// Implementation
}
If this one is ok - what is @MaskFormat("###-##-####")
good for?
Upvotes: 0
Views: 1287
Reputation: 242686
Your URI pattern has two problems:
;
as a delimiter and trim the URI (for example Tomcat's bug 30535). So, as a workaround you may use some different character, like ,
.So, you'll have something like
@RequestMapping(value = "/{planet}/{lat:.*},{long:.*}", method = RequestMethod.GET)
Note that since you disabled Spring's extension handling, you have to enable it manually if you need it (this also requires more restrictive regexp to avoid confusing decimal point with extension separator):
@RequestMapping(value =
{"/{planet}/{lat:.*},{long:\\d+\\.\\d+}",
"/{planet}/{lat:.*},{long:\\d+\\.\\d+}.*"},
method = RequestMethod.GET)
By @MaskFormat
you probably mean an annotation from mvc-showcase
(note that it's note a built-in annotation). Along with MaskFormatAnnotationFormatterFactory
it demonstrates the new formatting faclilities to convert path variables (i.e. strings) to method arguments. Actually it converts String
s to String
s, so it's used only for validation.
Upvotes: 2