如何理解play2异常的结果解析器?
这是来自 play2 内置 zentasks 的示例代码:
object Project {
// -- Parsers
/**
* Parse a Project from a ResultSet
*/
val simple = {
get[Pk[Long]]("project.id") ~
get[String]("project.folder") ~
get[String]("project.name") map {
case id~folder~name => Project(id, folder, name)
}
}
}
请注意字段键:project.id
、project.folder
、project.name
。
project
部分是什么意思?它从哪里来?
看一下查询方法:
def findById(id: Long): Option[Project] = {
DB.withConnection { implicit connection =>
SQL("select * from project where id = {id}").on(
'id -> id
).as(Project.simple.singleOpt)
}
}
SQL是select * from project ...
,结果应该是:
id | folder | name
不是:
project.id | project.folder | project.name
为什么要把key指定为project.???
,但不是直接字段名称
?
play2 如何使用 project.
部分?
This is a sample code from play2's built-in's zentasks:
object Project {
// -- Parsers
/**
* Parse a Project from a ResultSet
*/
val simple = {
get[Pk[Long]]("project.id") ~
get[String]("project.folder") ~
get[String]("project.name") map {
case id~folder~name => Project(id, folder, name)
}
}
}
Please notice the field keys: project.id
, project.folder
, project.name
.
What does the project
part mean? Where is it come from?
Look at the query method:
def findById(id: Long): Option[Project] = {
DB.withConnection { implicit connection =>
SQL("select * from project where id = {id}").on(
'id -> id
).as(Project.simple.singleOpt)
}
}
The SQL is select * from project ...
, the result should be:
id | folder | name
Not:
project.id | project.folder | project.name
Why we should specify the keys as project.???
, but not field name
directly?
How play2 use the project.
part?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 这里,Anorm Parser 使用提供的字符串来检索给定的列。
当它获取一些元数据时,它需要该字段的完整范围(表+名称)才能工作。
As per the code available in here, Anorm Parser uses the string provided to retrieve the given column.
As it gets some metadata, it requires teh full scope of the field (table + name) to work.
恕我直言,这只是数据库别名。
等于
或什至
IMHO it's just DB alias.
is the same as
or even