view is not rendered when returning ModelAndView
I have the following problem. I need开发者_如何学Go to export a PDF in a controller
The code below, where I return a View, works as expected.
@RequestMapping(method = RequestMethod.GET)
public View exportReport(
@RequestParam(value = "userName", required = true) String userName,
@RequestParam(value = "startDate", required = true) Date startDate,
@RequestParam(value = "endDate", required = true) Date endDate) {
///////////////////////////////////////////
return new TimeSheetReportPdfView();
}
The problem occurs if I change the method to return a ModelAndView:
@RequestMapping(method = RequestMethod.GET)
public ModelAndView exportReport(
@RequestParam(value = "userName", required = true) String userName,
@RequestParam(value = "startDate", required = true) Date startDate,
@RequestParam(value = "endDate", required = true) Date endDate) {
///////////////////////////////////////////
return new ModelAndView(new TimeSheetReportPdfView(), model);
}
Now, the PDF is not exported, all I get is a blank page and nothing in the logs.
Update:
public class TimeSheetReportPdfView extends AbstractPdfView {
@SuppressWarnings("unchecked")
@Override
protected void buildPdfDocument(Map model, Document document,
PdfWriter writer, HttpServletRequest request, HttpServletResponse response)
throws Exception {
}
Any help appreciated.
Thanks.
Well, I found the cause for this behavior. Apparently, when I imported ModelAndView, I accidentally imported it from org.springframework.web.portlet instead org.springframework.web.servlet.
Thanks anyway for your feedback.
精彩评论