publicclassMyPdfViewextendsAbstractPdfView {@OverrideprotectedvoidbuildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request,
HttpServletResponse response) throws Exception {
List list = (List) model.get("list");
for (int i = 0; i < list.size(); i++) {
//将数据加载到视图上
document.add(new Paragraph((String)(list.get(i))));
}
}
在controller中
@RequestMapping("/pdf")
public ModelAndView mypdf() {
ModelAndView mav = new ModelAndView();
//添加自定义视图
mav.setView(new MyPdfView());
List list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add(i+"");
}
mav.addObject("list", list);
return mav;
}
@RequestMapping("/excle")
public ModelAndView myexcle() {
ModelAndView mav = new ModelAndView();
//添加视图
mav.setView(new MyExcelView());
List list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add(i+"");
}
mav.addObject("list", list);
return mav;
}