已经通过联合查询将结果集存储在 Map 中,
现在需要将 map中的部分数据作为 excel 的列名,然后导出 excel,
网上搜索安利,大都是获取 Bean 中的数据,很少有以查询的结果集作为数据源的,
谢谢,
谢谢大家的帮助,这个问题解决了,参考了: ‘不会代码的小白’ 的安利
[SSM 数据库数据导出excel](https://www.cnblogs.com/xswz/p/7257658.html "")
//实现类
@Override
public List<Map<String, String>>
selectAllAssetInlibraryInfo(String pkweeksetmenu) {
List<Map<String, String>> getFspendByTem=
new ArrayList<Map<String, String>>();
getFspendByTem = this.ifspendrecordService.
getFspendByTemStr(pkweeksetmenu);
List<Map<String, String>> mapList =
new ArrayList<Map<String,String>>();
if (getFspendByTem.size() >0) {
for (Map<String, String> map : getFspendByTem) {
Map<String, String> mapA = new HashMap<String, String>();
String payamount = (String)map.get("payamount");
String weekmenun = map.get("setmenu");//套餐名称
String menun = map.get("menu");//菜单名称
String menuname = weekmenun + " " +menun;
mapA.put("手机号", map.get("phone"));
mapA.put("中文名", map.get("psnname"));
mapA.put("退餐详情", menuname);
mapA.put("退款金额", payamount);
mapList.add(mapA);
}
}
return mapList;
}
//controller
@RequestMapping("exportcs")
public ModelAndView exportcs(HttpServletRequest request,
String pkweekmenu, ModelMap map) throws Exception{
List<Map<String,String>> list =
fweeksetmenuService.selectAllAssetInlibraryInfo(pkweekmenu);
String[] titles={"手机号","中文名","退餐详情","退款金额"};
ViewExcel excel=new ViewExcel(titles);
map.put("excelList", list);
return new ModelAndView(excel,map);
}