From the course: Spring Web MVC 6

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Add repository and Controller methods

Add repository and Controller methods - Spring Tutorial

From the course: Spring Web MVC 6

Add repository and Controller methods

- [Instructor] The next part of this use case is to work on the product details flow. So the first step is to add a method in the ProductRepository to get product details specific to a product id. So on the ProductRepository class, let's open that. And we are just going to add a method, very similar to searchByName that we added on line 15. So I'll just grab these two lines, lines 14 and 15, copy them, come down there and paste it. And this time this is only one product that you're going to get because you are trying to search by the id. So it's not going to be a list of products. So let's change that return type. The name should be searchById because that's what we want to do. And the parameter will be id in this case. And the Query on line 20 should change to select p from Product p where p.id, and we are not going to use the like clause, we'll use a perfect match with the help of the equal to operator. And this…

Contents