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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.19.220