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