我正在尝试构建Uri,但是Query方法会给我类型不匹配,预期的字符串,实际的Uri.Query
def buildUri(url: String, query: Option[Map[String, String]] = None): Uri = {
val fullUrl = endpoint + (if (endpoint.endsWith("/")) url else "/" + url)
val uri: Uri = query match {
case Some(map) if map.nonEmpty =>
Uri(fullUrl.toString).copy(query = Query(map))
case _ =>
Uri(fullUrl.toString)
}
uri
}
答案 0 :(得分:0)
我想这就是你想要做的:
def buildUri(url: String, query: Option[Map[String, String]] = None): Uri = {
val fullUrl = endpoint + (if (endpoint.endsWith("/")) url else "/" + url)
val uri: Uri = query match {
case Some(map) if map.nonEmpty =>
Uri(fullUrl.toString).withQuery(query = Query(map))
case _ =>
Uri(fullUrl.toString)
}
uri
}