具有多个查询可选参数的控制器映射不起作用

时间:2018-10-22 15:33:33

标签: micronaut

我想将请求映射到处理如下URL的控制器:

/weather?city=London
/weather?city=London&country=GB

注意城市和国家/地区是可选参数

这个简单的控制器是:

@Controller("/weather")
class WeatherController(...) {

    @Get(produces = [MediaType.APPLICATION_JSON])
    fun getWeather(city: String?, country: String?): Flux<Any> = ...

但是似乎存在一些映射问题:

java.lang.NoSuchMethodError: com.codependent.weatherapp.controller.WeatherController.getWeather(Ljava/lang/String;Ljava/lang/String;)Lreactor/core/publisher/Flux;
    at com.codependent.weatherapp.controller.$WeatherControllerDefinition$$exec1.invokeInternal(Unknown Source)
    at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:145)

更新:该项目位于Github上。

我尝试了几种方法来映射可选参数,但是没有一个起作用:

1)遵循URI路径变量文档 http://localhost:8080/weather/test1

@Get(value = "/test1{?city,country,cityIds}", produces = [MediaType.APPLICATION_JSON])
fun getWeather(city: Optional<String>, country: Optional<String>, cityIds: Optional<String>) = "The weather is...".toMono()

2)仅表示可选内容,没有实际的请求参数映射-http://localhost:8080/weather/test2

@Get(value = "/test2", produces = [MediaType.APPLICATION_JSON])
fun getWeather2(city: Optional<String>, country: Optional<String>, cityIds: Optional<String>) = "The weather is...".toMono()

3)Kotlin方式,仅表示参数的可空性-http://localhost:8080/weather/test3

@Get(value = "/test3", produces = [MediaType.APPLICATION_JSON])
fun getWeather3(city: String?, country: String?, cityIds: String?) = "The weather is...".toMono()

1 个答案:

答案 0 :(得分:0)

项目正常,似乎IntelliJ存在一个问题,该问题无法正确构建。我更改了建筑配置,将流程委派给Gradle并解决了问题。

我感谢@James Kleeh的支持。享受Micronaut!