这是我的代码:
package controllers
import play.api._
import play.api.mvc._
import play.api.data.Form
import play.api.data.Forms.tuple
import play.api.data.Forms.text
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
val form = Form(
tuple(
"name" -> text,
"address" -> text,
"x_card_num" -> text
)
)
def payment = Action { implicit request =>
def values = form.bindFromRequest.data
def name = values("name")
//val card_num = ""
//values.isDefinedAt("x_card_num")
if (values.get("x_card_num") == None) {
val card_num = "test"
} else {
//def card_num = values("x_card_num")
val card_num = "test2"
}
//val card_num = "test"
Ok(views.html.payment("testing",name,card_num))
}
}
它不起作用。它只是为了完全跳过 if (values.get("x_card_num") == None) 和 else 语句,并且 card_num 最终为空字符串,如 if else 语句之前定义的那样。
为什么它会完全忽略 if else 语句?
以及如何检查数组“值”中是否存在键?