Spring Boot Path Variable Annotation | Rest Controller | Rest API

Опубликовано: 19 Февраль 2022
на канале: 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.


Смотрите видео Spring Boot Path Variable Annotation | Rest Controller | Rest API онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Senol Atac 19 Февраль 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 338 раз и оно понравилось 4 людям.