【问题标题】:Locations - problem with array/list as optional param位置 - 数组/列表作为可选参数的问题
【发布时间】:2020-09-25 13:34:07
【问题描述】:

请求 A:http://localhost:8080/api/organizations/1/scenarios?perProducts=1

请求 B:http://localhost:8080/api/organizations/1/scenarios?perProducts=1,2

我的位置类:

            @Location("/scenarios")
            data class Scenarios(
                val organization: Organization,
                val startValue: Int = 0,
                val perPage: Int = 10,
                val perProducts: List<Int> = listOf(),
                val byName: String = ""
            )

如果我向路径(请求 a)添加一个产品 ID,一切正常,但如果我添加两个(请求 b)或更多 ID,我会收到“错误请求”作为响应。我哪里错了?

【问题讨论】:

    标签: kotlin ktor


    【解决方案1】:

    试试这个:

    http://localhost:8080/api/organizations/1/scenarios?perProducts=1&perProducts=2
    

    后台位置使用Data Convertion 功能,这是它处理多个值的一种方式。

    【讨论】:

    • 太棒了!应该记录在案。
    猜你喜欢
    • 2019-11-09
    • 2019-03-29
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2011-05-27
    • 2021-12-06
    相关资源
    最近更新 更多