我想将 play 2.0 框架中的表单绑定与从circumflex-orm ( website ) 扩展 Record 的类结合起来。
这些是我的类对象:
class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
def this(name: String, description: String) = {
this()
this.name := name
this.description := description
}
val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
val name = "name".VARCHAR(255).NOT_NULL
val description = "description".TEXT.NOT_NULL
def PRIMARY_KEY = id
def relation = Task
}
这就是我试图用播放形式做的事情:
val taskForm: Form[Tasks] = Form(
mapping(
"name" -> text,
"description" -> text
)
{(name, description) => Task(name, description)}
{(t: Task) => Option(t.name(), t.description()) }
)
但我收到这样的错误:
found : models.Task => Option[(String, String)]
required: Unit => Option[(String, String)]
{(t: Task) => Option(t.name(), t.description())}
如果我用一些替换选项:
found : models.Task => Some[(String, String)]
required: Unit => Option[(String, String)]
{(t: Task) => Some(t.name(), t.description())}
我现在一无所知,任何提示将不胜感激。
非常感谢。
编辑:我犯了一个基本错误,我确实命名了表格:
val taskForm: Form[Tasks] = Form(
当类的名称是“任务”时。所以我可以将其更改为:
val taskForm: Form[Task] = Form(
mapping(
"name" -> text,
"description" -> text
) ( (name, description) => Task )
( (t: Task) => Option() )
)
现在我得到一个不同的错误:
Unspecified value parameter x
( (t: Task) => Option() )
我在eclipse中做了一个需要依赖的简单项目,你可以在这里下载并查看它,如果有帮助: 基本表单示例