Performance: @GetMapping for GET requests
This affects server response time and client perceived loading speed by handling HTTP GET requests efficiently.
@GetMapping("/data") public CompletableFuture<String> getData() { return CompletableFuture.supplyAsync(() -> { // Simulate async processing try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return "Data"; }); }
@GetMapping("/data") public String getData() { // Heavy synchronous processing try { Thread.sleep(5000); // Simulate delay } catch (InterruptedException e) { e.printStackTrace(); } return "Data"; }
| Pattern | Server Thread Usage | Response Delay | Impact on LCP | Verdict |
|---|---|---|---|---|
| Synchronous blocking @GetMapping | Blocks thread during processing | High delay (e.g., 5s) | Increases LCP significantly | [X] Bad |
| Asynchronous @GetMapping with CompletableFuture | Non-blocking, frees threads | Response delayed but server handles concurrency better | Improves LCP under load | [OK] Good |
@GetMapping annotation in a Spring Boot application?/hello using @GetMapping in Spring Boot?/welcome?
@GetMapping("/welcome")
public String welcome() {
return "Welcome to Spring Boot!";
}@GetMapping("/user/{id}")
public String getUser(@PathVariable int userId) {
return "User ID: " + userId;
}/product/{category}/{id} and returns a string combining both path variables. Which of the following method signatures correctly uses @GetMapping and @PathVariable annotations?Pass the test and this pattern moves unknown