@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";
}