SoFunction
Updated on 2025-03-04

Feign uses @PathVariable

Feign uses @PathVariable

In Feign, you can use@PathVariableAnnotation to insert variables into the URL.

This is with Spring MVC@PathVariableThe usage is the same.

Here is an example

public interface MyClient {

 @RequestMapping(method = , value = "/users/{userId}")
 User getUser(@PathVariable("userId") String userId);
}

In this example

getUser(String userId)The method will send a GET request to/users/{userId}

{userId}is a placeholder whose value is@PathVariable("userId")supply.

To call this method, you can look like this:

public void doSomething() {
 User user = ("123");
 // ...
}

When actually calling

Feign will"123"Replace to the URL{userId}The URL to be requested will be/users/123

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.