Book Image

Spring MVC: Beginner's Guide - Second Edition

By : Amuthan Ganeshan
Book Image

Spring MVC: Beginner's Guide - Second Edition

By: Amuthan Ganeshan

Overview of this book

Spring MVC helps you build flexible and loosely coupled web applications. The Spring MVC Framework is architected and designed in such a way that every piece of logic and functionality is highly configurable. Also, Spring can integrate effortlessly with other popular web frameworks such as Struts, WebWork, Java Server Faces, and Tapestry. The book progressively teaches you to configure the Spring development environment, architecture, controllers, libraries, and more before moving on to developing a full web application. It begins with an introduction to the Spring development environment and architecture so you're familiar with the know-hows. From here, we move on to controllers, views, validations, Spring Tag libraries, and more. Finally, we integrate it all together to develop a web application. You'll also get to grips with testing applications for reliability.
Table of Contents (20 chapters)
Spring MVC Beginner's Guide - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Chapter 3, Control Your Store with Controllers


Questions

Answers

If you imagine a web application called Library with the following request mapping on a Controller class level and in the method level, which is the appropriate request URL to map the request to the books method?

@RequestMapping("/books")    
public class BookController {    
...    
    
@RequestMapping(value = "/list")    
public String books(Model model) {    
...    

1. http://localhost:8080/library/books/list

Similarly, suppose we have another handler method called bookDetails under BookController as follows, what URL will map to that method?

@RequestMapping    
public String details(Model model) {    
...   

2. http://localhost:8080/library/books

If we have a web application called webstore with the following request mapping on the Controller class level and in the method level, which is the appropriate request URL?

@RequestMapping("/items")    
public class ProductController {    
...    
@RequestMapping(value = "/type/{type}", method =   RequestMethod.GET)    
public String productDetails(@PathVariable("type")   String productType, Model model) {   

2. http://localhost:8080/webstore/items/type/electronics

For the following request mapping annotation, which are the correct methods' signatures to retrieve the path variables?

@RequestMapping(value="/manufacturer/{   manufacturerId}/product/{productId}")    

1. public String productByManufacturer(@PathVariable String manufacturerId, @PathVariable String productId, Model model)

4. public String productByManufacturer (@PathVariable("manufacturerId") String manufacturer, @PathVariable("productId") String product, Model model)

For the following request mapping method signature, which is the appropriate request URL?

@RequestMapping(value = "/products", method =   RequestMethod.GET)    
public String productDetails(@RequestParam String rate,   Model model)   

2. http://localhost:8080/webstore/products?rate=400