From the course: Spring: Spring MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Access data from Model

Access data from Model

From the course: Spring: Spring MVC

Start my 1-month free trial

Access data from Model

- [Instructor] Now that we have added the database introduction code, let's modify the SearchController to call repository and set the data of search results inside the Model object. So let's go back to (mumbles). Go to the SearchController, and we're going to make sure that we invoke the repository implementation from here. Now in Spring, it can be very easily done with the autowired annotation. So you just have to make sure that the product repository is dependency injected into SearchController, and that is done with autowired annotation. So I'm going to say ProductRepository, let's take a variable, and then let's come down to the search method on line 22. I'm just going to create a list first of Product. Let's label it as products, and you can create a new ArrayList object. And then to this, we assign the products that are coming out of the database code, which is ProductRepository.searchByName. And this…

Contents