Building a RESTful Web Service :: Learn how to create a RESTful web service with Spring. :: spring-boot http://spring.io/guides/gs/rest-service/

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