Learn Java for Web Development

(Tina Meador) #1
CHAPTER 5: Building Java Web Applications with Spring Web MVC 249

Let’s replace the interface-based controller in Listing 5-42 with an annotations-based controller.
Listing 5-44 illustrates the annotations-based BookController.


Listing 5-44. Annotations-Based BookController



  1. package com.apress.bookstore.controller;

  2. import com.apress.bookstore.service.BookService;

  3. import org.springframework.stereotype.Controller;

  4. import org.springframework.web.bind.annotation.RequestMapping;

  5. import org.springframework.web.bind.annotation.RequestMethod;

  6. import org.springframework.web.servlet.ModelAndView;



  7. @Controller

  8. @RequestMapping("/list_book.html")


Figure 5-20. Directory structure of the bookstore application

Free download pdf