gpt4 book ai didi

java - Playframework 从嵌套 Controller 加载表单

转载 作者:行者123 更新时间:2023-12-01 13:45:55 24 4
gpt4 key购买 nike

我想将表单从嵌套 Controller 传递到 View 。

这是我的设置:

app
|
--controllers
|
--appointment
|
-- Appointment.java


|
-- views
|
-- appointment
|
-- create.scala.html

路线:

# Appointment
GET /appointment/create controllers.appointment.Appointment.create()
POST /appointment controllers.appointment.Appointment.validate()

预约类(class):

public class Appointment extends Controller {

public static Result create() {
List<Procedure> procedures = Procedure.find.all();
List<Employee> doctors = Employee.find.where().eq("role", "doctor").findList();
return ok(create.render(Form.form(CreateAppointment.class), procedures, doctors));

}

public static Result validate(){
Form<CreateAppointment> registerForm = Form.form(CreateAppointment.class).bindFromRequest();

return badRequest(create.render(registerForm));
}

public static Result edit(Integer id) {
return TODO;
}

public static Result delete(Integer id) {
return TODO;
}

public static Result all() {
return TODO;
}

public static class CreateAppointment {

public Date endDate;
public Date startDate;

public String reason;

public String validate() {
if (startDate.after(endDate))
return "End date must be after start Date";

return null;
}

}

}

创建.scala.html

@(form: Form[controllers.appointment.routes.Appointment.CreateAppointment],procedures: List[Procedure],doctors: List[Employee])
<html>
<head> </head>
<body>

@helper.form(controllers.appointment.routes.Appointment.create) {

问题出在这里 -> form: Form[__ROUTE___]问题是我不知道如何正确传递 CrateAppointment。

我已经尝试过:

controllers.appointment.routes.Appointment.CreateAppointment
Appointment.CreateAppointment
ppointment.Appointment.CreateAppointment

我收到错误

[error] MyPath\app\views\appointment\create.scala.html:1: type CreateAppointment is not a member of controllers.appointment.ReverseAppointment

最佳答案

在 PlayFramework 中, Controller 中的每个包都有自己的路由包。例如,您要查找的 url 是以下两个路由之一:

controllers.appointment.routes.Appointment.create()
controllers.appointment.routes.Appointment.validate()

关于java - Playframework 从嵌套 Controller 加载表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20377698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com