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
- 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 |
- 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 |
-
For the sortBy argument, configure a default value of 'name' (the default for when a request parameter is not passed)
-
Now for method
deleteProductById, add a method argument of typeStringthat maps to the path variable 'id'
VERIFICATION
- Start the training application and go to the app home page
- 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
- 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
- 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