问题
I have a Spring Boot/Kotlin web application and a controller that takes a query param.
Here's my controller method:
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ResponseBody
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
...
@GetMapping("/items")
@ResponseBody
@Produces(MediaType.APPLICATION_JSON_VALUE)
fun getItems(@QueryParam("n") count: Int? = null): Collection<MyItem> {
return myItemService.list(count)
}
The following cURL results in a null count
parameter:
curl http://localhost:8080/items?n=25
Instead, Spring Boot always uses the variable name as the query param value:
curl http://localhost:8080/items?count=25
What gives? Is this a bug in Spring Boot, or did the Spring team intentionally ignore the documentation on how @QueryParam
should work and choose to favor variable name over annotation value?
来源:https://stackoverflow.com/questions/60725696/spring-boot-kotlin-ignore-value-field-of-queryparam