View Javadoc
1   package com.lucidtech.puttingalltogether.controller;
2   
3   import com.lucidtech.puttingalltogether.model.Greeting;
4   import org.springframework.web.bind.annotation.GetMapping;
5   import org.springframework.web.bind.annotation.RequestParam;
6   import org.springframework.web.bind.annotation.RestController;
7   
8   import java.util.concurrent.atomic.AtomicLong;
9   
10  import static java.lang.String.format;
11  
12  @RestController
13  public class GreetingController {
14  
15      private static final String template = "Hello, %s!";
16      private final AtomicLong counter = new AtomicLong();
17  
18      @GetMapping("/greeting")
19      public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
20          return new Greeting(counter.incrementAndGet(), format(template, name));
21      }
22  }