Path variable with Spring Boot

In the last post "Query parameter handling with Spring Boot"  we have seen how to provide the query parameter . I will be using same project and extending HelloController for this.

For RESTful service to access specific resource via their Id/name we would also need path variable so that those can be accessed with specific path like "hello/{id}".

This can be achieved with @ PathVariable annotation. Replace the with below code.

package hello;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class HelloController {
    public String sayHello(@PathVariable("id") String id) {
        return  String.format("Hello world with Spring Boot !!! Id used here %s", id);

Run the application and hit http://localhost:8080/hello/myId in your browser. You should get "Hello world with Spring Boot !!! Id used here myId" in return. 


Popular posts from this blog

How to flash CWM Recovery to Samsung Galaxy SL( GT-I9003) using Odin

Exception handling with RestTemplate

Warning : Hardcoded string "str", should use @string resource