Answer the question
In order to leave comments, you need to log in
How to make a redirect in a controller with JSON in SpringMVC?
Good time!
A JSON object comes from the front, I accept it in the controller:
@ResponseBody
@PostMapping(value = "controller", consumes = "application/json")
public SomeDto controller(@RequestBody SomeDto someDto, Authentication authentication) {
...
}
@ResponseBody
@PostMapping(value = "controller", consumes = "application/json")
public String controller(@RequestBody SomeDto someDto, Authentication authentication, ModelMap modelMap) {
String username;
try {
username = authentication.getName();
} catch (Exception e) {
String message = "Unauthorized user";
LOG.warn(message);
return "login";
}
UserDto userDto = userService.getUser(username);
someDto.setUser(userDto);
modelMap.addAttribute("someDto", someDto);
return "another-page";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question