我有一个视图,从我向Controller发送请求的位置,结果将响应返回到视图页面。现在我想将ajax响应传递给下一个Controller,但我不知道Controller中的响应类型是什么 这是我的ajax代码:
$.ajax({
type: "POST",
url: "<c:url value="/menu/menucheckout/${restaurant_menu.name}"/>",
data : {"amount":amount, "orderoption" :orderoption, "date":date , "time":time ,'menuitemsArray': menuitemsArray ,'menuPriceArray': menuPriceArray , 'menuSpiceeArray': menuSpiceeArray , 'ItemQuantityArray': ItemQuantityArray },
success: function(response){
console.log(response);
window.location.href = "/BistroServicesMenuApp/welcome/getordercheckout/"+response.model;
}
});
这是菜单控制器
@Controller
@RequestMapping(value = "/menu")
public class MenuController {
@Autowired
private MenuTypeService menutypeService;
@RequestMapping(value="/menucheckout/{restaurantname}" ,method = RequestMethod.POST )
@ResponseBody
public ModelAndView menucheckout(@PathVariable("restaurantname") String restaurantname , HttpSession session, HttpServletRequest request, HttpServletResponse response) throws SQLException, NamingException, IOException
{
ModelAndView model = new ModelAndView("/welcome/getordercheckout");
System.out.println("COMING IN menucheckout CONTROLLER" + restaurantname);
System.out.println("orderoption" + request.getParameter("orderoption"));
String amount = request.getParameter("amount");
String orderoption = request.getParameter("orderoption");
String date = request.getParameter("date");
String time = request.getParameter("time");
String[] menuitemsArray = request.getParameterValues("menuitemsArray[]");
String[] menuPriceArray = request.getParameterValues("menuPriceArray[]");
String[] menuSpiceeArray = request.getParameterValues("menuSpiceeArray[]");
String[] ItemQuantityArray = request.getParameterValues("ItemQuantityArray[]");
model.addObject("restaurantname", restaurantname);
model.addObject("amount", amount);
model.addObject("orderoption", orderoption);
model.addObject("date", date);
model.addObject("time", time);
model.addObject("menuitemsArray", menuitemsArray);
model.addObject("menuPriceArray", menuPriceArray);
model.addObject("menuSpiceeArray", menuSpiceeArray);
model.addObject("ItemQuantityArray", ItemQuantityArray);
return model;
}
}
现在这是第二个控制器&#34; OrderController&#34;:
@Controller
@RequestMapping("/welcome")
public class OrderController {
@Autowired
private OrderService orderService;
@RequestMapping("/getordercheckout/{response}")
public ModelAndView getOrderCheckOut(@PathVariable("response") ModelAndView response)
{
ModelAndView model = new ModelAndView("/getordercheckout");
model.addObject("response" , response);
System.out.println("Response : " +response);
return model;
}
现在我想得到回复,但我不确定响应的数据类型是什么。
System.out.println打印此错误:
ModelAndView: reference to view with name '[object Object]'; model is null
请帮助我,因为我是Spring MVC的新手。 提前谢谢。