rest - With Spring 3.0, can I make an optional path variable? -
with spring 3.0, can have optional path variable?
for example
@requestmapping(value = "/json/{type}", method = requestmethod.get) public @responsebody testbean testajax( httpservletrequest req, @pathvariable string type, @requestparam("track") string track) { return new testbean(); }
here /json/abc
or /json
call same method.
1 obvious workaround declare type
request parameter:
@requestmapping(value = "/json", method = requestmethod.get) public @responsebody testbean testajax( httpservletrequest req, @requestparam(value = "type", required = false) string type, @requestparam("track") string track) { return new testbean(); }
and /json?type=abc&track=aa
or /json?track=rr
work
you can't have optional path variables, can have 2 controller methods call same service code:
@requestmapping(value = "/json/{type}", method = requestmethod.get) public @responsebody testbean typedtestbean( httpservletrequest req, @pathvariable string type, @requestparam("track") string track) { return gettestbean(type); } @requestmapping(value = "/json", method = requestmethod.get) public @responsebody testbean testbean( httpservletrequest req, @requestparam("track") string track) { return gettestbean(); }
Comments
Post a Comment