【发布时间】:2014-12-08 02:01:29
【问题描述】:
我真的不太了解 Play Framework 如何与 Java 交互(我使用 Eclipse 作为 IDE)
所以如果我的解释有点难以理解,请多多包涵
我想要做的是一个 1 页的网页 (localhost:9000),它可能看起来像这样:
http://i.stack.imgur.com/JtRFF.png (我只有 1 个代表,所以我认为不能放图片;只是一个链接)
我需要知道的事情:
1) HTTP 方法如何与 Playframework 交互
2) 如何删除、编辑条目
目前我只知道如何填充学生
来自 controllers.Application.Java 的代码:
public static Result addStudents(){
Student student = Form.form(Student.class).bindFromRequest().get();
student.save();
return redirect(routes.Application.index());
}
public static Result getStudents(){
List<Student> students = new Model.Finder(String.class, Student.class).all();
return ok(toJson(students));
}
models.Student.java 中的代码
@Entity
public class Student extends Model{
@Id
public String Id;
public String name;
public String course;
}
views.index.scala.html 中的代码
(我使用 Java 而不是 scala,但我真的不知道区别所以我保留了 intex。 scala.html)
@main("Welcome to Play") {
<form action="@routes.Application.addStudents()" method="post">
<input name="name">
<input course="course">
<input type="submit">
</form>
}
来自 conf.evolutions.routes 的代码
POST /student controllers.Application.addStudents()
GET /student controllers.Application.getStudents()
【问题讨论】:
-
w,为什么我会无缘无故被否决?我的问题无关紧要还是我做错了什么?
标签: java javascript playframework xmlhttprequest