Reputation: 490
How to send the redirect from Spring controller if the return type is not String for the URL Handkler method.
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ResponseBody
public JsonResponse save(@RequestBody FormBean formBean) {
if(condition true)
? Save(formBean)
: "redirect:/anotherUrl";
}
So JsonResponse which is a return type is actually a java class, how do i send redirect here ?
Upvotes: 1
Views: 1057
Reputation: 58094
You have to return a ResponseEntity
from your controller method. It has an HttpStatus‘ and headers you can set, and a body that is your domain object. To redirect you would normally set the status to
FOUND(302) and add a
Location` header with the URL for the client to redirect.
Upvotes: 1