无法在@ResponseBody中使用@ModelAttribute

时间:2015-03-17 16:14:08

标签: spring jsp spring-mvc displaytag modelattribute

我有一个要求,在ajax调用中我需要填充表格。我正在使用jquery ajax和spring mvc。下面是我用来使用modelattribute填充bean的代码,但是当我转到jsp时,modelattribute根本不可用。任何帮助都会非常明显。

@RequestMapping(value = "/getFullSchedule", method = RequestMethod.GET, produces="application/json")
public @ResponseBody ScheduleBean displayFullSchedule(@ModelAttribute("scheduleBean") ScheduleBean scheduleBean,
        @RequestParam(value= "callCenterId", required=true, defaultValue = "-1") String callCenterId,
        @RequestParam(value= "queueId", required=true, defaultValue = "-1") String queueId, Model model)
        throws ServiceException {

    logger.debug("Getting full schedule for callCenterId(" + callCenterId + ") and queueId(" + queueId + ")"); 

    QueueScheduleFull fullSchedule = scheduleService.get7DaySchedule(callCenterId, queueId);

    logger.debug(fullSchedule);


//  ScheduleBean scheduleBean = new ScheduleBean();
    scheduleBean.setCallCenterId(fullSchedule.getCallCenterId());
    scheduleBean.setQueueId(fullSchedule.getQueueId());
    scheduleBean.setVdnDesc(fullSchedule.getVdnDesc());

    Collection<DaySchedule> days = new ArrayList<DaySchedule>();
    days.add(fullSchedule.getWeeklySchedule().getMonday());
    days.add(fullSchedule.getWeeklySchedule().getTuesday());
    days.add(fullSchedule.getWeeklySchedule().getWednesday());
    days.add(fullSchedule.getWeeklySchedule().getThursday());
    days.add(fullSchedule.getWeeklySchedule().getFriday());
    days.add(fullSchedule.getWeeklySchedule().getSaturday());
    days.add(fullSchedule.getWeeklySchedule().getSunday());
    scheduleBean.setDays(days);
    model.addAttribute("scheduleBean", scheduleBean);
    model.addAttribute("chetan", "test");
    return scheduleBean;
}

jsp部分如下所示

<c:out value="HELLO${chetan}"></c:out>

    <c:out value="Help me out here${scheduleBean.days[0].startTime}"/>

    <display:table htmlId="scheduleTable" name="${scheduleBean.days}" pagesize="15" 
        export="false" sort="list" cellpadding="0" cellspacing="0"
        width="100%" requestURI="" id="fullScheduleTable" align="left" class="pure-table pure-table-bordered">

        <display:column title = "abc">
            <div>${fullScheduleTable.startTime}</div>
        </display:column>
    </display:table> 

jsp页面上没有模型或ModelAttribute中的任何内容。

我还在调度程序-servlet中添加了jackson映射器,但仍然没有。

<mvc:annotation-driven />
<bean id="jacksonMessageConverter"
    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />

0 个答案:

没有答案