BAEL-542 use @GetMapping annotation

This commit is contained in:
Tomasz Lelek 2017-02-05 10:39:29 +01:00 committed by Andrew Morgan
parent dce9a947ab
commit c2ed9afc2d
1 changed files with 8 additions and 9 deletions

View File

@ -6,9 +6,8 @@ import com.baeldung.cachecontrol.model.UserDto;
import org.springframework.http.CacheControl;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
@ -17,27 +16,27 @@ import java.util.concurrent.TimeUnit;
@Controller
public class ResourceEndpoint {
@RequestMapping(value = "/default/users/{name}", method = RequestMethod.GET)
public ResponseEntity<UserDto> getUserWithDefaultCaching(@PathVariable(value = "name") String name) {
@GetMapping(value = "/default/users/{name}")
public ResponseEntity<UserDto> getUserWithDefaultCaching(@PathVariable String name) {
return ResponseEntity.ok(new UserDto(name));
}
@RequestMapping(value = "/users/{name}", method = RequestMethod.GET)
public ResponseEntity<UserDto> getUser(@PathVariable(value = "name") String name) {
@GetMapping(value = "/users/{name}")
public ResponseEntity<UserDto> getUser(@PathVariable String name) {
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS))
.body(new UserDto(name));
}
@RequestMapping(value = "/timestamp", method = RequestMethod.GET)
@GetMapping(value = "/timestamp")
public ResponseEntity<TimestampDto> getServerTimestamp() {
return ResponseEntity.ok()
.cacheControl(CacheControl.noStore())
.body(new TimestampDto(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli()));
}
@RequestMapping(value = "/private/users/{name}", method = RequestMethod.GET)
public ResponseEntity<UserDto> getUserNotCached(@PathVariable("name") String name) {
@GetMapping(value = "/private/users/{name}")
public ResponseEntity<UserDto> getUserNotCached(@PathVariable String name) {
return ResponseEntity.ok()
.body(new UserDto(name));
}