/
LevelController.java
28 lines (25 loc) · 1.16 KB
/
LevelController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package hello;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import static java.lang.String.format;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@Controller
public class LevelController {
@RequestMapping(value = "/greeting", method = GET)
@ResponseBody
public HttpEntity<Greeting> greet(
@RequestParam(value = "name", required = false,
defaultValue = "World") final String name) {
final Greeting greeting = new Greeting(format("Hello, %s!", name));
greeting.add(linkTo(methodOn(LevelController.class).greet(name)).
withSelfRel());
return new ResponseEntity<>(greeting, OK);
}
}