1.添加按钮
<span style="font-size:18px;"><input id="btnExport" class="btn btn-primary" type="button" value="导出Excel" /></span>
</pre><pre name="code" class="html">
2.js
$("#btnExport").click(
function() {
/* 显示一个带"确定"和"取消"按钮的确认消息窗口 */
top.$.jBox.confirm("确认要导出用户数据吗?", "系统提示", function(
v, h, f) {
if (v == "ok") {
$("#searchForm1").attr("action",
"${ctx}/wish/wishUser/export");
$("#searchForm1").submit();
}
}, {
/* 表示第几个按钮为默认按钮,索引从0开始 */
buttonsFocus : 1
});
top.$('.jbox-body .jbox-icon').css('top', '55px');
});
3.修改控制类
<span style="font-size:18px;">@RequiresPermissions("sys:user:view")
@RequestMapping(value = "export", method= RequestMethod.POST)
public String exportFile(WishUser user, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
try {
String fileName = "用户数据"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<WishUser> page = wishUserService.findPage(new Page<WishUser>(request, response, -1), user);
new ExportExcel("用户数据", WishUser.class).setDataList(page.getList()).write(response, fileName).dispose();
return null;
} catch (Exception e) {
addMessage(redirectAttributes, "导出用户失败!失败信息:"+e.getMessage());
}
return "redirect:" + adminPath + "/sys/user/list?repage";
}</span>
4.修改实体类 在需要导出的字段get上添加
<span style="font-size:14px;">@Length(min=0, max=128, message="头像url长度必须介于 0 和 128 之间")
<span style="white-space:pre"> </span>@ExcelField(title="头像url", type=1, align=2, sort=1)
<span style="white-space:pre"> </span>public String getAvatar() {
<span style="white-space:pre"> </span>return avatar;
<span style="white-space:pre"> </span>}</span>