Scala 使用分页的播放路线的最佳实践?
我对玩2(Scala)相当陌生。我需要使用分页来输出列表的成员。这很容易,除了分页部分 在我的路线文件中,我有我的搜索:Scala 使用分页的播放路线的最佳实践?,scala,pagination,routes,playframework-2.0,Scala,Pagination,Routes,Playframework 2.0,我对玩2(Scala)相当陌生。我需要使用分页来输出列表的成员。这很容易,除了分页部分 在我的路线文件中,我有我的搜索: GET /find/thing/:type controllers.Application.showType(type: String) 如果我想将整个列表转储到页面中,这很好 现在,如果我想给它分页呢?我想我可以做- GET /find/thing/:type/:page controllers.Applicatio
GET /find/thing/:type controllers.Application.showType(type: String)
如果我想将整个列表转储到页面中,这很好
现在,如果我想给它分页呢?我想我可以做-
GET /find/thing/:type/:page controllers.Application.showType(type: String, page: Int)
但是,如果用户只键入“myurl.com/find/thing/bestThing”而没有页面,会发生什么呢?显然,当它自动“默认”到第1页时,会出现错误
有没有办法默认这些参数?如果没有,这方面的最佳做法是什么
谢谢大家! 有两种选择:
/find/thing/something/
重定向到/find/thing/something
(第1页)GET /find/thing/:type controllers.Application.showType(type: String, page: Int ?= 1)
/find/thing/something?page=123
GET /find/thing/:type controllers.Application.showType(type: String, page: Int ?= 1)
/find/thing/something?page=123
对于页码,可以使用查询字符串参数而不是路径参数。查询字符串参数将允许您在缺少参数时提供默认值
GET /find/thing/:type controllers.Application.showType(type: String, page: Int ?= 1)
您可以这样使用它们:
/find/thing/bestThing?page=3 // shows page 3
/find/thing/bestThing // shows page 1
谢谢,之所以选择您的答案,是因为您的答案有不止一个好的解决方案。