接jeefast导出
选择数据导出(选择什么导出什么)
代码看上面的,都一样,唯一改变的就是
js页面
//导出
exportExcel: function () {
var studentIds = ".";
if(getSelectedIds()!=null){
studentIds = getSelectedIds();
}
window.top.location.href = baseURL + "platform/student/exportExcel?studentIds="+studentIds+"&token="+token;
},
使用方法选中HTML页面勾选的编号
就是选这里的多选框
运用的是id选择器进行筛选值
下面的表格是连接的js页面,这个id就是前面复选框的
//选择多条记录--导出用
function getSelectedIds() {
var grid = $("#jqGrid");
var rowKey = grid.getGridParam("selrow");
if(!rowKey){
return ;
}
return grid.getGridParam("selarrrow");
}
Controller
/**
* 导出用户
* @throws IOException
*/
@Log("导出用户")
@RequestMapping("/exportExcel")
@RequiresPermissions("platform:student:exportExcel")
public void exportExcel(HttpServletResponse response, HttpServletRequest request) throws IOException{
String studentIds = request.getParameter("studentIds");
List<PfStudent> studentList = new ArrayList<PfStudent>();
if (!studentIds.equals(".")) {
String ids[] = studentIds.split(",");
List<Integer> idList = new ArrayList<Integer>();
for (int i = 0; i < ids.length; i++) {
idList.add(Integer.parseInt(ids[i]));
}
studentList = pfStudentService.selectBatchIds(idList);
}else {
studentList = pfStudentService.selectList(new EntityWrapper<PfStudent>());
}
OutputStream os = response.getOutputStream();
Map<String, Object> params = new HashMap<String, Object>();
// List<PfStudent> studentList = (List<PfStudent>)pfStudentService.queryList(params);
// OutputStream os = response.getOutputStream();
Map<String, String> map = new HashMap<String, String>();
map.put("title", "用户信息表");
map.put("total", studentList.size()+" 条");
map.put("date", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
//响应信息,弹出文件下载窗口
response.setContentType("application1/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode("用户信息表.xls", "UTF-8"));
ExcelTemplate et = ExcelUtil.getInstance().handlerObj2Excel("web-info-template.xls", studentList, PfStudent.class, true);
et.replaceFinalData(map);
et.wirteToStream(os);
os.flush();
os.close();
}