返回新的ModelAndView不起作用

时间:2018-06-30 16:02:29

标签: java ajax spring spring-mvc

我的控制器:

@RequestMapping(value="/testAdmin", method = RequestMethod.POST,consumes = "application/json")
public ModelAndView testAdmin(@RequestBody Student student) {
    System.out.println(student.getName()+" "+student.getId()+" "+student.getLogin()+" "+student.getPassword());
    return new ModelAndView("showString","student",student.getName());
}

我的ajax函数:

 function test2(a,ob) {
    var student={
        id:ob[a].id,
        login:ob[a].login,
        password:ob[a].password,
        name:ob[a].name
    }
    $.ajax({
        type: "POST",
        contentType : 'application/json; charset=utf-8',

        url: "testAdmin",
        data: JSON.stringify(student),
        success: function (response)
        {
            alert("success");
        },
        error : function(xhr, status, errorThrown) {
            alert(status+" "+errorThrown.toString());
        }
    });
}

控制器方法有效,但不会转到其他页面。 我不知道该如何解决,请举一个例子或阅读的信息

0 个答案:

没有答案