我已经设法在我的控制器中制作了一个 modelAndView 来做我对 ui 的期望,但有时我需要通过 post man 对其进行测试,所以当我尝试模型属性始终为空时,有人可以解释到底发生了什么吗?
这是我使用的控制器:
@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!");
}
}