我正在寻找在spring mvc中ajax成功后返回值的列表。
@RequestMapping(value = "/getAlertNotification.ftl")
public ModelAndView getAlertNotification(HttpServletRequest request
){
Map<Object, Object> model = new HashMap<Object, Object>();
User user = RequestUtils.getUser(request);
List<CardRequestNotification> Cardreqlist=cardRequestManager.cardRequestNotification(user);
model.put("listObj", Cardreqlist);
return new ModelAndView(new JSONView(model));
}
$("#alertLink").click(function()
{ var $this = j$(this);
GtsJQuery.ajax(GtsJQuery.getContextPath()
+ "/getAlertNotification.ftl",
function(data) {
/* how i return Cardreqlist object list`enter code here` in here */
});发布于 2017-01-17 22:04:13
我猜你有一个误解,如果你试图返回一个ModelAndView,那么你需要指定将要呈现的JSP文件或HTML模板,并且你需要特定的ModelAndView名称。
但是您混合了视图和JSON,JSON是用于AJAX调用的,所以我猜您的代码可能更像这样:
@RequestMapping(value = "/getAlertNotification.ftl")
@ResponseBody
public List<CardRequestNotification> getAlertNotification(HttpServletRequest request) {
Map<Object, Object> model = new HashMap<Object, Object>();
User user = RequestUtils.getUser(request);
List<CardRequestNotification> Cardreqlist = cardRequestManager.cardRequestNotification(user);
model.put("listObj", Cardreqlist);
return Cardreqlist;
}然后在你的JS代码中,你可以这样做:
data.Cardreqlisthttps://stackoverflow.com/questions/41698334
复制相似问题