Java 带有预填充数据的表单
我有一张新员工的表格要填写。但是现在,我想要一个编辑表单,它返回用户填写的表单 这是我的控制器:Java 带有预填充数据的表单,java,forms,playframework,playframework-2.0,Java,Forms,Playframework,Playframework 2.0,我有一张新员工的表格要填写。但是现在,我想要一个编辑表单,它返回用户填写的表单 这是我的控制器: public static Result updateForm(String id) { Form<staffInfo> existingStaffForm = Form.form(staffInfo.class); staffInfo existingStaff = staffInfo.find.byId(id); return ok(
public static Result updateForm(String id) {
Form<staffInfo> existingStaffForm = Form.form(staffInfo.class);
staffInfo existingStaff = staffInfo.find.byId(id);
return ok(
views.html.update.render(existingStaffForm.fill(existingStaff))
);
}
我的路线是:
GET /staff/:id/update controllers.Application.updateForm(id:String)
我想,问题出在href标签上。有人能帮你把链接放在正确的位置吗?显然
现有的员工是空的
,不知怎么调试它。i、 e:
public static Result updateForm(String id) {
Form<staffInfo> existingStaffForm = Form.form(staffInfo.class);
staffInfo existingStaff = staffInfo.find.byId(id);
if (existingStaff==null) {
return badRequest("Oooops existingStaff not found in DB... ");
}
return ok(
views.html.update.render(existingStaffForm.fill(existingStaff))
);
}
公共静态结果更新表单(字符串id){
formexistingstaffform=Form.Form(staffInfo.class);
staffInfo existingStaff=staffInfo.find.byId(id);
if(existingStaff==null){
返回badRequest(“数据库中找不到OOPS existingStaff…”);
}
返回ok(
views.html.update.render(existingStaffForm.fill(existingStaff))
);
}
顺便说一句:按照惯例,模型的类名应该以大写字母开头:StaffInfo
您应该使用反向路由生成a href
@routes.WhateverYourControllerIsNamed.updateForm("id")
见你好@biesior!谢谢你的帮助!事实上,我在等待你的答案,因为你回答了大多数与游戏框架相关的问题:)是的,我注意到了类名。我以后再换!:顺便说一下,我发现我的代码的主要问题是什么!请参考以上内容。我更新了我的问题:)
public static Result updateForm(String id) {
Form<staffInfo> existingStaffForm = Form.form(staffInfo.class);
staffInfo existingStaff = staffInfo.find.byId(id);
if (existingStaff==null) {
return badRequest("Oooops existingStaff not found in DB... ");
}
return ok(
views.html.update.render(existingStaffForm.fill(existingStaff))
);
}
@routes.WhateverYourControllerIsNamed.updateForm("id")