Spring REST、Kotin 和默认原始参数导致错误

标签 spring kotlin spring-rest

我得到一个错误:

Optional long parameter 'count' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type

当我尝试调用此 REST Controller 时。

    @RequestMapping("/api/audio/tracks", produces = arrayOf(APPLICATION_JSON_VALUE))
    interface SomeApi {


        @RequestMapping(method = arrayOf(GET))
        fun list(@RequestParam("count", defaultValue = "10") count: Long): Any
    }

spring不看defaultValue吗?

如何解决这类问题?

!Kotlin 默认值也不起作用

最佳答案

我在我的情况下找到了解决方案:

原因是因为一个接口(interface)。当我在实现中放置 @RequestParam("count", required = false, defaultValue = "10") 时,一切都开始工作了。

关于Spring REST、Kotin 和默认原始参数导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46548489/

相关文章:

android - kotlin 中内联函数的正确用法是什么?

android - 当使用空列表和 minifyEnabled true 序列化模型时,Jackson 序列化失败,并抛出 KotlinReflectionInternalError

java - 如何在 Controller 上获取在 web.xml 上定义为默认 servlet 映射的端点的请求?

java - 使用 Confluence Kafka Avro Serializer 进行 Spring Kafka 测试找不到 ZKClientConfig

java - API请求(GET调用)是否可以向客户端返回响应并启动后台任务来完成请求

java - 模拟休息服务服务器 : how to mock a POST call with a body?

java - 为 bean 添加属性

java - 如何从kotlin接口(interface)访问java接口(interface)中定义的常量

java - 如何设置 spring-data-rest 的默认媒体类型?