我尝试保存并显示与 play webframework 2.0 的多对一关系...
我有这些模型:
@Entity
public class Project extends Model{
@Id
public Long id;
@Required
public String name;
@ManyToMany
public List<Worker> workers =
new ArrayList<Worker>();
@ManyToOne
public Worker head;
...
}
@Entity
public class Worker extends Model{
@Id
public Long id;
@Required
public String name;
...
public static Map<String,String> options() {
LinkedHashMap<String,String> options = new LinkedHashMap<String,String>();
for(Worker w: Worker.getAll()) {
options.put(w.id.toString(), w.name);
}
return options;
}
}
我有这样的看法:
@(projects: List[Project], taskForm: Form[Project])
@import helper._
<h1>@projects.size() Projects(s)</h1>
<ul>
@for(project <- projects) {
<li>
@project.name
<b> - head: </b>
@project.head.name
<ul>
@for(worker <- project.workers) {
<li>
@worker.name
</li>
}
</ul>
@form(routes.ProjectController.deleteProject(project.id)) {
<input type="submit" value="Delete">
}
</li>
}
</ul>
<h2>Add a new task</h2>
@form(routes.ProjectController.newProject()) {
@inputText(taskForm("name"))
@inputText(taskForm("description"))
@select(
taskForm("head.id"),
options(Worker.options),
'_label -> "Worker"
)
<input type="submit" value="Create">
}
但是当我保存项目时,我的头脑中没有相关的工作人员,也没有找到任何多对多的例子。任何人都可以告诉我如何在 play 2.0 中管理关系或给我一个解释它的链接吗?
感谢所有回复