diff --git a/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java b/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java index 9f756b5ab4..bd129cbdfa 100644 --- a/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java +++ b/spring-security-cache-control/src/main/java/com/baeldung/cachecontrol/ResourceEndpoint.java @@ -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 getUserWithDefaultCaching(@PathVariable(value = "name") String name) { + @GetMapping(value = "/default/users/{name}") + public ResponseEntity getUserWithDefaultCaching(@PathVariable String name) { return ResponseEntity.ok(new UserDto(name)); } - @RequestMapping(value = "/users/{name}", method = RequestMethod.GET) - public ResponseEntity getUser(@PathVariable(value = "name") String name) { + @GetMapping(value = "/users/{name}") + public ResponseEntity 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 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 getUserNotCached(@PathVariable("name") String name) { + @GetMapping(value = "/private/users/{name}") + public ResponseEntity getUserNotCached(@PathVariable String name) { return ResponseEntity.ok() .body(new UserDto(name)); }