jeefast导出Excel

jeefast导出Exceljeefast导入Excel
entity层
要先把数据库字段和Excel关联,想导出谁就在谁的get方法写注解
title是Excel字段名,order是从左向右的排序
在这里插入图片描述
在这里插入图片描述
dao层

//导出
	List<PfStudent> queryList(Map<String, Object> map);

service层

/**
	 * 查询用户列表---导出
	 */
	List<PfStudent> queryList(Map<String, Object> map);

serviceImpl层

//导出
	@Override
	@DataFilter(tableAlias = "pst", user = false)
	public List<PfStudent> queryList(Map<String, Object> map){
		return pfStudentDao.queryList(map);
	}

controller层

/**
	 * 导出用户
	 * @throws IOException
	 */
	@Log("导出用户")
	@RequestMapping("/exportExcel")
	@RequiresPermissions("platform:student:exportExcel")
	public void exportExcel(HttpServletResponse response) throws IOException{
		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();
	}

	//图片上传
	public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception {
		File targetFile = new File(filePath);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		FileOutputStream out = new FileOutputStream(filePath +"/"+ fileName);
		out.write(file);
		out.flush();
		out.close();
	}

dao.xml文件

<select id="queryList" resultType="PfStudent">
		select pst.*, (select pc.classes_class from pf_classes pc where pc.classes_id = pst.student_class) classes_class from pf_student pst
		<where>
			<if test="studentName != null and studentName.trim() != ''">
				and pst.`student_name` like concat('%',#{studentName},'%')
			</if>
			<!--  数据过滤  -->
			${filterSql}
		</where>
	</select>

html

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

js

//导出
		exportExcel: function () {
			window.top.location.href = baseURL + "platform/student/exportExcel?token="+token;
		},

还需要给其授予权限
在这里插入图片描述

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值