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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Basic annotations for controllers4m 20s
-
(Locked)
Create a controller with request mapping4m
-
(Locked)
@RequestParam in Controller5m 37s
-
(Locked)
Add database code3m 7s
-
(Locked)
Access data from Model8m 15s
-
(Locked)
@ModelAttribute: Add JSP pages4m 55s
-
(Locked)
@ModelAttribute: Access model attributes on JSP6m 7s
-
(Locked)
@ModelAttribute: Add Spring form tag library5m 15s
-
(Locked)
Test the application6m 37s
-
(Locked)
-
-
-
-
-
-
-