jeefast框架:实现导出功能

jeefast框架:实现导出功能

在主界面中,设置【导出】功能键

				<a v-if="hasPermission('platform:student:exportExcel')" class="btn btn-primary btn-sm" @click="exportExcel"><i class="fa fa-trash-o"></i>&nbsp;导出</a>

xml配置项

<select id="selectBatchIds" resultType="cn.jeefast.modules.platform.entity.Student">
		SELECT pn.* , su.`username` createrName,c.cname cname,g.gname gname
		FROM pf_student pn
		INNER JOIN pf_class c ON pn.cid=c.cid
		inner join pf_grade g on c.gid=g.gid
		LEFT JOIN sys_user su ON su.`user_id`=pn.`creater`
		where id in
		<foreach item="ids" collection="list" open="(" separator="," close=")">
			#{ids}
		</foreach>
	</select>

js中【导出】功能选中功能

exportExcel: function () {
			var noticeIds=getSelectedRows();
			if(noticeIds == null){
				var ids=0;
			}else{
				var ids=noticeIds.join(",");
			}
			window.top.location.href = baseURL + "platform/student/exportExcel?token="+token+"&ids="+ids;
		},

实体类

//@ExcelResources :这个注释是用来导出某个数据的。
//title这个就是在导出的xls文件中某一列中命名一个名字,作为列名
//order 这个是用来将这个属性第几次取出数据
@ExcelResources(title = "学生ID",order=1)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

Dao,Service 层的代码,就省略不写了 🙂,原因是方法是它封装好了的,我们直接调用它就行。

@Log("导出用户")
	@RequestMapping("/exportExcel")
	@RequiresPermissions("platform:student:exportExcel")
	public void exportExcel(HttpServletResponse response,HttpServletRequest request) throws Exception{
		Map<String, Object> params = new HashMap<String, Object>();
		List<Student> userList = null;
		List<Long> ids = new ArrayList<Long>();
		String str=request.getParameter("ids");
		System.out.println(str);
		if (str.equals("0") || str == "0") {
			userList = studentService.selectList(new EntityWrapper<Student>());
		}else {
			String[] noticeIds =  str.split(",");
			for (int i = 0; i < noticeIds.length; i++) {
				ids.add(Long.parseLong(noticeIds[i]));
			}
			userList = studentService.selectBatchIds(ids);
		}
		OutputStream os = response.getOutputStream();

		Map<String, String> map = new HashMap<String, String>();
		map.put("title", "学生信息表");
		map.put("total", userList.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", userList, Student.class, true);
		et.replaceFinalData(map);
		et.wirteToStream(os);
		os.flush();
		os.close();
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

平平常常一般牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值