Created
July 6, 2018 08:05
-
-
Save tiiime/4b02a299908467003eb024f471b5e46c to your computer and use it in GitHub Desktop.
http 分页
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def makePageResponse[T <: List[Any]](list: T, start: Int, max: Int, getNextUrl: Map[String, String] => String) = { | |
var nextUrl: Option[String] = None | |
var preUrl: Option[String] = None | |
if (list.nonEmpty && list.size == max) { | |
nextUrl = Some(getNextUrl(Map( | |
"start" -> (start + max).toString, | |
"max" -> max.toString | |
))) | |
} | |
if (list.nonEmpty && start > 0) { | |
preUrl = Some(getNextUrl(Map( | |
"start" -> (start - max).max(0).toString, | |
"max" -> max.toString | |
))) | |
} | |
Response.build(list, nextUrl, preUrl) | |
} | |
private final val URL ="" | |
private nextUrl(map:Map[String,String])=Uri(URL).withQuery(Query(map)).toString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment