jeefast导出Excel,jeefast导入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> 导出</a>
js
//导出
exportExcel: function () {
window.top.location.href = baseURL + "platform/student/exportExcel?token="+token;
},
还需要给其授予权限