我在控制器中有方法
@PostMapping("/process")
suspend fun process(
@RequestParam("id") id: String,
@RequestParam("names") names: List<String>,
@RequestParam("repositoryUri") repositoryUri: String
) = coroutineScope {
...
}
我想从前端桌面应用程序发送查询,然后尝试
val post = HttpPost(uri)
val builder: MultipartEntityBuilder = MultipartEntityBuilder.create()
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
builder.addTextBody("id", id, ContentType.DEFAULT_BINARY) // id is String, that is Ok
builder.addTextBody("names", names, ContentType.DEFAULT_BINARY) // names is List<String>, error
builder.addTextBody("repositoryUri", repositoryUri, ContentType.DEFAULT_BINARY) // Ok
val entity: HttpEntity = builder.build()
post.entity = entity
httpclient.execute(post)
但是控制器方法(names
)中的第二个参数不是字符串。该构建器只有方法addTextBody和addBinaryBody(但似乎不合适)
我该怎么办?
P.S。我用apache
您需要一种自定义格式来将字符串列表作为http形式参数发送。