-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.java
More file actions
36 lines (29 loc) · 877 Bytes
/
Copy pathApplication.java
File metadata and controls
36 lines (29 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package controllers;
import play.*;
import play.mvc.*;
import play.db.jpa.*;
import views.html.*;
import models.Person;
import play.data.FormFactory;
import javax.inject.Inject;
import javax.swing.text.Document;
import java.util.List;
import static play.libs.Json.*;
public class Application extends Controller {
@Inject
FormFactory formFactory;
public Result index() {
return ok(index.render());
}
@Transactional
public Result addPerson() {
Person person = formFactory.form(Person.class).bindFromRequest().get();
JPA.em().persist(person);
return redirect(routes.Application.index());
}
@Transactional(readOnly = true)
public Result getPersons() {
List<Person> persons = (List<Person>) JPA.em().createQuery("select p from Person p").getResultList();
return ok(toJson(persons));
}
}