开发者

PLay framework Routing with multiple parameters issue

I don't seem to be able to resolve the following scenario where no routes are found.

Got my route file with the following entry:


GET     /reports/items/{date}                          Reports.items(field:'all')

and the controller defined with


public static void items(@Required Date date, String field){
...
}

the view is using @{items(date)} or @{items(date,'all')}

the url translates 开发者_开发问答to: localhost:9000/reports/items/19-07-2011?field=all

I always seem to get not found with:


tried the following route
GET       /                                                 Reports.index
GET       /reports/items/{date}                             Reports.items 

Any idea on how I can route and default field to 'all' if it is not provided?


I believe what you need is this:

GET       /reports/items/{date}                     Reports.items(field:'all') 
GET       /reports/items/{date}/{field}             Reports.items 

First the system will match the request with only date (which will use 'all' as default value for field).

If it doesn't match, because you added the field, it will go to the second GET where both parameters will be mapped to the controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜