Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Spring Task | Spring Boot Basics
Spring Boot Backend
course content

Зміст курсу

Spring Boot Backend

Spring Boot Backend

1. Backend Development Basics
2. Spring Boot Basics
3. RESTful API
4. Working with Databases
5. Testing Backend Applications

Spring Task

Task

You will need to continue the implementation of the application from the previous chapter and develop the logic for searching for a product by name.

Note

Use the HTTP GET method to pass the product name in the URL parameters and retrieve this name using the @RequestParam annotation.

Implementation Logic

Repository Level

You already have a method with an empty implementation in the ProductRepository class. This method is intended to search for products by name. You need to implement this method.

Signature

Note

If the Product is not found, return an null.

Service Level

Next, move to the service layer in the ProductService class to call the findByName() method from the repository.

Signature

You need to implement the logic to retrieve the product by its name from the repository and pass it to the controller layer.

Note

You do not need to implement any business logic in the service. In this example, the service will act as a layer between the repository and the controller.

Controller Level

Now, implement the findProductsByName() method in the ProductRestController to add a new endpoint for searching products by name.

You can use the GET method with the URL /find, passing the name as a parameter. Use the @RequestParam annotation to retrieve it in the method parameters.

Signature

Example request: localhost:8080/find?name=product1

Все було зрозуміло?

Секція 2. Розділ 6
We're sorry to hear that something went wrong. What happened?
some-alt