Learn Java for Web Development

(Tina Meador) #1
CHAPTER 8: Play with Java and Scala 375


  1. public static Result newBook() {

  2. return TODO;

  3. }



  4. public static Result deleteBook(Long id) {

  5. return TODO;

  6. }



  7. }


   Lines 7, 11, and 15: These lines show the actions that were specified in the
routes file in Listing 8-7.
 Lines 8, 12, and 16: A built-in result TODO is used that returns “Not
implemented” response 503. This result tells Play 2 that the action
implementations will be provided later. When you access the application via
http://localhost:9000/books, you see the result displayed in Figure 8-22.

Figure 8-22. Built-in TODO result in Play 2


Creating the Model

The next step is to define the model Book that can be stored in a relational database. For this, create
a class in the app/models/Book.java file, as illustrated in the Listing 8-9.


Listing 8-9. Book.java



  1. package models;

  2. import java.util.*;

  3. public class Book {

  4. public Long id;

  5. public String label;

  6. public static List all() {

  7. return new ArrayList();

Free download pdf