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

GreetingController.java 667B

1234567891011121314151617181920
  1. package hello;
  2. import java.util.concurrent.atomic.AtomicLong;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RequestParam;
  5. import org.springframework.web.bind.annotation.RestController;
  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(),
  13. String.format(template, name));
  14. }
  15. }