GreetingController.java

  1. package com.lucidtech.puttingalltogether.controller;

  2. import com.lucidtech.puttingalltogether.model.Greeting;
  3. import org.springframework.web.bind.annotation.GetMapping;
  4. import org.springframework.web.bind.annotation.RequestParam;
  5. import org.springframework.web.bind.annotation.RestController;

  6. import java.util.concurrent.atomic.AtomicLong;

  7. import static java.lang.String.format;

  8. @RestController
  9. public class GreetingController {

  10.     private static final String template = "Hello, %s!";
  11.     private final AtomicLong counter = new AtomicLong();

  12.     @GetMapping("/greeting")
  13.     public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
  14.         return new Greeting(counter.incrementAndGet(), format(template, name));
  15.     }
  16. }