我有一个使用 hibernate-gorm 构建的简单 micronaut 3.0.3 应用程序。
尝试发送这样的 GET 请求时出现以下错误http://localhost:8080/?commentId=1
Failed to convert argument [command] for value [null] due to: Specified value [1] is not of the correct type: class java.lang.Long (through reference chain: com.example.PostCommand[\"commentId\"])
此代码适用于 Micronaut 版本 2.5.12。我搜索了有关此的迁移指南,但找不到有关该部门任何更改的任何提及。
邮政指令:
package com.example
import grails.gorm.annotation.Entity
import org.grails.datastore.gorm.GormEntity
@Entity
class PostCommand implements GormEntity<PostCommand> {
String title
String content
Long commentId
void setCommentId(Long commentId) {
this.commentId = commentId
}
void setCommentId(String commentId) {
this.commentId = Long.valueOf(commentId)
}
}
后控制器:
package com.example
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
@Controller('/')
class PostController {
@Get('{?command*}')
HttpResponse search(HttpRequest request, PostCommand command){
HttpResponse.ok()
}
}
删除所有设置器或仅删除字符串类型的设置器时,它可以工作。
这是任何感兴趣的人的github链接。
任何的意见都将会有帮助。