我们可以在java akka http中有一个默认参数吗?

p4tfgftt  于 2022-11-23  发布在  Java
关注(0)|答案(1)|浏览(99)

如以下代码所示

post(() -> route(
                    pathPrefix("scheduleStatus", () ->
                            path("send", () ->
                                    parameter("type", type ->
                                            entity(Jackson.unmarshaller(Car.class), car -> {
                                                return complete(car.getColor());
                                            })
                                    )

                            )
                    ))

我们可以为类型设置默认值吗?比如我们认为默认汽车类型是宝马等?我们如何在java akka http中实现这一点?

nwsw7zdq

nwsw7zdq1#

根据文档,您无法使用parameter()执行此操作-您需要使用parameterOptional()

post(() -> route(
        pathPrefix("scheduleStatus", () ->
            path("send", () ->
                parameterOptional("type", type ->
                    entity(Jackson.unmarshaller(Car.class), car -> {
                        return complete(car.getColor());
                    })
                )
            )
        )
    )

相关问题