Exercise 15: Query and Path Variables - jkneal/spring-angular-train GitHub Wiki

Goals

Learn how to accept request input in controller methods, including query parameters and path variables.

Instructions

  1. In edu.train.product.InventoryController, map the following controller methods to the specified path and Http method:
Method Path Http Method
searchProducts "/inventory/search" Get
deleteProductById "/inventory/delete/{id}" Post
  1. Now for method searchProducts, add the following method arguments that map to the specified request (query) parameter:
Argument Type Request Parameter
searchTerm String searchTerm
sortBy String sortBy
  1. For the sortBy argument, configure a default value of 'name' (the default for when a request parameter is not passed)

  2. Now for method deleteProductById, add a method argument of type String that maps to the path variable 'id'

VERIFICATION

  1. Start the training application and go to the app home page
  2. Click on the link 'Ex 15 Search'. Verify you get the result:

You invoked controller method:

Search

Search Term is apples

Sort By is id

  1. Now go back to the menu and click on the link 'Ex 15 Default Sort'. Verify you get the result:

You invoked controller method:

Search

Search Term is apples

Sort By is name

  1. Now go back to the menu and click on the link 'Ex 15 Delete By Id'. Verify you get the result:

You invoked controller method:

Delete Product By Id

Delete Product Id is 311