@ModelAndView在ui中按预期工作,但邮递员发送json请求时不起作用

时间:2019-02-12 21:13:11

标签: json spring-boot spring-mvc request modelandview

我已经设法在控制器中制作了一个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!");

    }
}

0 个答案:

没有答案
相关问题