gpt4 book ai didi

scala - Play 2.X ScalaRouting bool 参数

转载 作者:行者123 更新时间:2023-12-04 05:14:56 24 4
gpt4 key购买 nike

如何在路由定义中使用 bool 值?

如果我用这种方式,

GET     /user/:userName   controllers.AppController.user(userName, registerDone:Boolean?=0)

它抛出这个错误:

[error]  found   : Int(0)
[error] required: Boolean


如果我用这种方式,
GET     /user/:userName   controllers.AppController.user(userName, registerDone:Boolean?=false)

它抛出这个错误:

bad request at: /user/aajjblack?registerDone=true, Cannot parse parameter registerDone as Boolean: should be 0 or 1



Controller :
public static Result user(final String userName, Boolean registerDone) {
}

最佳答案

使用... Int相反

GET  /user/:userName  controllers.AppController.user(userName, registerDone: Int?=0)

行动:
public static Result user(final String userName, int registerDone) {
if(registerDone == 0){
return badRequest();
}

// do something with registered user...
return ok();
}

这是任何类型 bool 值的最简单替换,因为您可以检查是否 registerDone大于 0(并且它仍然保持类型安全)。

关于scala - Play 2.X ScalaRouting bool 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com