I have managed to make a modelAndView in my controller doing what Im expecting from the ui, but sometimes I need to test it via post man so when I tried the model attribute is always null, can someone explain what is happening exactly?
here is the controller that im using:
@Controller
public class LoginController extends AuthenticationBase {
@Autowired
private AuthenticationInterfaceImpl authentication;
Logger logger = LoggerFactory.getLogger(LoginController.class);
@GetMapping("/login_form")
public ModelAndView login(@ModelAttribute LoginForm loginForm) {
return new ModelAndView("index");
}
@PostMapping("/login_form")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response,
@ModelAttribute LoginForm loginForm, BindingResult result) {
LoginInfo loginInfo;
try {
loginInfo = authentication.userLogin(loginForm.getUserName(), loginForm.getPassword());
if (loginInfo.getNewPasswordRequired()) {
return new ModelAndView("change_password", "change_password", loginForm.getUserName());
} else {
UserInfo userInfo = new UserInfo(loginInfo.getUserName(), loginInfo.getEmailAddr(), "");
return new ModelAndView("application", "application", userInfo);
}
} catch (Exception e) {
logger.error(e.getMessage());
}
return new ModelAndView("index", "authenticationError", "Password or user name error!");
}
}