RestEasy @Path Question with regular expression

a 夏天 提交于 2019-12-04 02:35:21

问题


Is it possible to define path with optional path variables.

like the uri below:

/app/make/{make}/model/{model}/year/{year}/mileage/{mileage}/fuelType/{fuelType}/maxPrice/{maxprice}/transmission/{transmission}/engineSize/{engineSize}

URI may be composed of any 0 or more combinations of the parameters? Is there a way to tell resteasy that all those paths are optional?

cheers.


回答1:


Why bother using path segments? If they are optional parameters then it can't be a real hierarchy so why not just use query string parameters. They work much better for this type of parameter.




回答2:


@Path("/make/{make}{model:(/model/[^/]+)?}{fuel : (/fuel/[^/]+)?}{gearbox : (/gearbox/[^/]+)?}/cars")



app/{make:(/make/[^/]+)?}{model:(/model/[^/]+)?}{year:(/year/[^/]+)?}{mileage:(/mileage/[^/]+)?}

I came up with the above workaround which works but inside the method I need to remove the pathname.



来源:https://stackoverflow.com/questions/4071008/resteasy-path-question-with-regular-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!