我得到一个错误:
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/