Skip to content

Commit

Permalink
Add redirect from root to /greeting
Browse files Browse the repository at this point in the history
Introduce a new endpoint that redirects requests from the root URL to the /greeting endpoint using RedirectView. This ensures users are automatically taken to the greeting page when accessing the root URL.
  • Loading branch information
jcardozo committed Sep 16, 2024
1 parent bf675a2 commit 0e3cd35
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;

@RestController
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@GetMapping("/")
public RedirectView redirectFromRootToDefaultEndpoint() {
return new RedirectView("/greeting");
}

@GetMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template, name));
Expand Down

0 comments on commit 0e3cd35

Please sign in to comment.