model.addAttribute() parameters
java, spring, spring-mvc
Solution
Yes, model is instantiated by spring and injected to your method, means if any of model attribute matches anything in request it will be filled. and it should be the last param in the method
model.addAttribute("products",products);
"products" is just a name which you can use it in your view get the value with `${products}`
Problem
I'm new to `Spring MVC` Framework. I'm doing some self study to extend my knowledge in Java. This is how I understand the `getProducts()` code definition from a tutorial I'm following but please correct me if I'm wrong. Controller requests something from the Data Access Object `>` Data Access Object gets the data from a Database or a Model through the `getProductList()` method `>` Stores the information to list `>` Then binds the list to the model. So I got two question about this. Is the inclusion of `model` as parameter in public `String getProducts(Model model)` considered the dependency injection Is `products` (within quotes) in `model.addAttribute("products",products);` just a name which I can change to whatever I like or should it match something? ``` public class HomeController { private ProductDao productDao = new ProductDao(); @RequestMapping("/") public String home(){ return "home"; } @RequestMapping("/productList") public String getProducts(Model model){ List<Product> products = productDao.getProductList(); model.addAttribute("products",products); return "productList"; //productList string is the productList.jsp which is a view } @RequestMapping("/productList/viewProduct") public String viewProduct(){ return "viewProduct"; } } ``` I'd appreciate any explanation or comment. Thank you.