'Spring doesn't see redirect command

I want to redirect one method from UserController to another in the same controller but when i redirect to my post method i only get blank page.

I've tried adding GetMapping("main-page") and redirecting to it but got the same issue. I only see response status 200 on the network page on the f12 panel. Index in get method is a view. Also when I change route in the redirect to e. g. 123123 or the same which doesn't exist I don't get a 404 error, only a white page with 200 status.

@Controller
@RequestMapping("users")
@AllArgsConstructor
public class UserController {
  private UserService userService;

  @GetMapping()
  public String getUsers(
      @Parameter(description = "Number of users shown", example = "size=1")
          @RequestParam(required = false, defaultValue = "3")
          int size,
      @Parameter(description = "Page number", example = "page=1")
          @RequestParam(required = false, defaultValue = "0")
          int page,
      @Parameter(description = "First name of required user", example = "firstName=Ivan")
          @RequestParam(required = false)
          String firstName,
      @Parameter(description = "Email of required user", example = "[email protected]")
          @RequestParam(required = false)
          String email,
      @Parameter(description = "Last name of required user", example = "lastName=Ivanov")
          @RequestParam(required = false)
          String lastName, Model model) {
    model.addAttribute("firstName", firstName);
    model.addAttribute("employee", new UserBodyRequest());
    model.addAttribute("employees", userService.findAll(page, size, new UserParamRequest(firstName, email, lastName)));
    return "index";
  }
    @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
          produces = {MediaType.APPLICATION_ATOM_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})   public String create(
          @Parameter(description = "User information")@Valid UserBodyRequest userBodyRequest,
          Model model) {
        model.addAttribute("employee", userBodyRequest);
        userService.create(userBodyRequest);
        return "redirect:users";   }


Solution 1:[1]

I would try to put slash in the redirecting line so it was redirect:/users. If it didn't fix the problem your description suggests that the culprit may be your templating engine. In that case I would recommend to explicitly set application.properties for it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ciszek