Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Spring Task | Section
Spring Boot Essentials

bookSpring Task

Glissez pour afficher le menu

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.

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

Product findByName(String name)

Service Level

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

Signature

Product getProductByName(String name);

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

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

Product findProductByName(@RequestParam String name);

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

Now, test to ensure everything is set up correctly. Navigate to the path /src/test/java/com/codefinity/springbootexmshop and run all the tests. They should pass successfully.

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 11

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Section 1. Chapitre 11
some-alt