Learn Java for Web Development

(Tina Meador) #1

218 CHAPTER 5: Building Java Web Applications with Spring Web MVC


Listing 5-18. BookService Interface


package com.apress.aop;


import java.util.List;


public interface BookService {
public List getAllBooks();


}


Listing 5-19 illustrates the implementation of this BookService.


Listing 5-19. BookService Implementation



  1. package com.apress.aop;



  2. import java.util.ArrayList;

  3. import java.util.List;



  4. public class BookServiceImpl implements BookService{

  5. private static List bookList;

  6. static {



  7. Book book1 = new Book();

  8. book1.setId((long)1);

  9. book1.setBookTitle("Modern Java");



  10. Book book2 = new Book();

  11. book2.setId((long)2);

  12. book2.setBookTitle("Beginning Groovy");



  13. Book book3 = new Book();

  14. book3.setId((long)2);

  15. book3.setBookTitle("Beginning Scala");



  16. bookList = new ArrayList();

  17. bookList.add(book1);

  18. bookList.add(book2);

  19. bookList.add(book3);

  20. }





  21. public List getAllBooks() {

  22. for(Book b: bookList){

  23. System.out.println("Books:"+b.getBookTitle());

  24. }

  25. return bookList;

  26. }

  27. }

Free download pdf