js
dc:function(){
window.top.location.href = baseURL + "xiangmu/ach/exportExcel?token="+token;
//调用控制台方法其中?token="+token不可省
},
控制台
/**
* 导出用户
* @throws IOException
*/
@Log("导出用户")
@RequestMapping("/exportExcel")//调用路径
@RequiresPermissions("platform:ach:exportExcel")//权限
public void exportExcel(HttpServletResponse response,HttpServletRequest request) throws IOException{
System.out.println();
List<Ach> acgList = achService.select();//获取导出数据
OutputStream os = response.getOutputStream();
Map<String, String> map = new HashMap<String, String>();
map.put("title", "学生成绩表");
map.put("total", acgList.size()+" 条");
map.put("date", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
//响应信息,弹出文件下载窗口
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode("学生成绩表.xls", "UTF-8"));
ExcelTemplate et = ExcelUtil.getInstance().handlerObj2Excel("web-info-template.xls", acgList, Ach.class, true);
et.replaceFinalData(map);
et.wirteToStream(os);
os.flush();
os.close();
}
实体类
@ExcelResources(title="成绩",order=4)//get方法加注解 第4列 名为成绩
public Double getAchi() {
return achi;
}
效果展示:
补充:传入数组后可用此方法遍历值
<select id="selectaid" resultType="cn.jeefast.xiangmu.entity.Ach">
select * from ach where aid in
<foreach item="aids" collection="array" open="(" separator="," close=")">
#{aids}
</foreach>
</select>