spring到出excel

[b]1.js&jsp[/b]
$("#excel").click(function() {
$("#form1").attr("action","<%=contextPath%>/admin/trainning/listtrainningtoexcel");
$("#form1").submit();
});



[b]2.backend[/b]
@RequestMapping(value = "admin/trainning/listtrainningtoexcel")
public ModelAndView listToExcel(
Trainning trainning,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "isEmployee", required = false) String isEmployee,
@RequestParam(value = "status", required = false) String status,
HttpServletRequest request) {
ModelAndView mav = new ModelAndView();
List> list = this.classService.searchTrainningList(
trainning, startDate, endDate, status, isEmployee);
mav.addObject("list", list);
mav.setViewName("admin/trainning/tosearchExcel.jsp");
return mav;
}


[b]3.tosearchExcel.jsp[/b]
<%@ page contentType="text/html; charset=UTF-8"%>


<%
String contextPath = request.getContextPath();
%>
<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "filename=TrainingDeliveryReportExcel.xls");
//response.setContentType("image/png");
%>





































姓名 状态 邮箱 部门/公司 产品线 课程代码 课程名字 培训结束日期
${list.user_name} ${list.status} ${list.email} ${list.department} ${list.modality} ${list.trainning_code} ${list.trainning_name}




你可能感兴趣的:(spring,java,spring,excel)