SpringBoot 2.2.2 + Vue(axios) + easypoi 4.3.0(boot版本)
EasyPOI 开发文档:http://doc.wupaas.com/docs/easypoi/easypoi-1c0u6ksp2r091
EasyPOI 官方示例:https://gitee.com/lemur/easypoi-test
使用easypoi简单导出功能,几行代码搞定导出。
如遇poi冲突,删除项目中其它poi的依赖,easypoi的依赖jar包将不会传递给pom文件,消除冲突
pom.xml 引入
<!--easypoi导入导出-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
导出对应的bean
@Data
@ExcelTarget("user")
public class User implements Serializable{
/**
* 用户名
*/
@Excel(name = "用户名",orderNum="0",width = 20)
private String userName;
/**
* 手机号
*/
@Excel(name = "手机号",orderNum="1",width = 15)
private String userPhone;
/**
* 用户类型
*/
@Excel(name = "用户类型",orderNum="2",width = 15)
private String userType;
}
@RestController
@RequestMapping("/userController ")
public class UserController extends BasicsController {
@Autowired
private UserService userService;
/**
*
* <p>Title: exportInfo</p>
* <p>Description: 导出</p>
* @param response
* @throws Exception
*/
@RequestMapping("/exportInfo")
public void exportInfo(@RequestBody RequestBean requestBean,LoginBean login,HttpServletResponse response) throws Exception {
Map<String, Object> map = requestBean.getData();
map.put("login", login);
List<User> list = userService.queryUserList(map);
ExcelUtil.exportExcel(list, null, "sheet1", User.class, "拜访记录", response);
}
}