我已经设法在控制器中制作了一个ModelAndView,以实现Im对UI的期望,但是有时我需要通过邮递员对其进行测试,因此当我尝试model属性始终为null时,有人可以确切解释发生了什么吗?
这是我正在使用的控制器:
@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!");
}
}