Home > Enterprise >  How do I execute two Mappings at once in SpringBoot by calling only the first mapping first?
How do I execute two Mappings at once in SpringBoot by calling only the first mapping first?

Time:10-02

@PostMapping(value = "/save")
public String saveRequest(@RequestBody Request request) {
    requestRepo.save(request);

    return "Saved...";
}

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public void method(HttpServletResponse httpServletResponse) {
    httpServletResponse.setHeader("Location", "https://www.google.com");
    httpServletResponse.setStatus(302);
}

Is there a way to execute the second mapping automatically after executing the first mapping? Or a way to mix/make this better?

EDIT: updated redirect mapping method

CodePudding user response:

@PostMapping(value = "/save")
public String saveRequest(@RequestBody Request request) {
    requestRepo.save(request);

    return "redirect:/to-be-redirected";
}
  • Related