Spring Boot Path Variable Annotation | Rest Controller | Rest API

Veröffentlicht am: 19 Februar 2022
auf dem Kanal: Senol Atac
338
4

Hi guys,

In this lesson, we will talk about spring path variables.

Spring provides a PathVariable annotation for rest api.
The @PathVariable annotation is used to handle template variables in the request URI mapping, and use them as method parameters.

Let’s check it for an example.

For example, if we use @PathVariable annotation to extract the templated part of the URI represented by the variable {userId},
We can send a request like /api/example/{userId}.
This request will invoke our example method with the extracted user-id value like 1234.
In spring, we can also specify the path variable name. In default, the path variable uses the same name with the parameter name. But we can customize it with the PathVariable name property.
In Spring, method parameters annotated with @PathVariable are required by default. But, PathVariable can be optional also.
We can set the required property of @PathVariable to false to make it optional.
We will see the details of it on our project.
That’s all for the beginning.
Thank you.


Auf dieser Seite können Sie das Online-Video Spring Boot Path Variable Annotation | Rest Controller | Rest API mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Senol Atac 19 Februar 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 338 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!