diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java index 61cdcd73..e110ec3c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java @@ -12,13 +12,17 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.annotation.Excel.ColumnType; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.PageDomain; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableSupport; +import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; /** * 表格相关 @@ -107,6 +111,44 @@ public class DemoTableController extends BaseController return prefix + "/export"; } + /** + * 表格导出选择列 + */ + @GetMapping("/exportSelected") + public String exportSelected() + { + return prefix + "/exportSelected"; + } + + /** + * 导出数据 + */ + @PostMapping("/exportData") + @ResponseBody + public AjaxResult exportSelected(UserTableModel userModel, String userIds) + { + List userList = new ArrayList(Arrays.asList(new UserTableModel[users.size()])); + Collections.copy(userList, users); + + // 条件过滤 + if (StringUtils.isNotEmpty(userIds)) + { + userList.clear(); + for (Long userId : Convert.toLongArray(userIds)) + { + for (UserTableModel user : users) + { + if (user.getUserId() == userId) + { + userList.add(user); + } + } + } + } + ExcelUtil util = new ExcelUtil(UserTableModel.class); + return util.exportExcel(userList, "用户数据"); + } + /** * 翻页记住选择 */ @@ -399,21 +441,26 @@ class UserTableModel private int userId; /** 用户编号 */ + @Excel(name = "用户编号", cellType = ColumnType.NUMERIC) private String userCode; /** 用户姓名 */ + @Excel(name = "用户姓名") private String userName; /** 用户性别 */ private String userSex; /** 用户手机 */ + @Excel(name = "用户手机") private String userPhone; /** 用户邮箱 */ + @Excel(name = "用户邮箱") private String userEmail; /** 用户余额 */ + @Excel(name = "用户余额", cellType = ColumnType.NUMERIC) private double userBalance; /** 用户状态(0正常 1停用) */ diff --git a/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html b/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html new file mode 100644 index 00000000..4aec88df --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html @@ -0,0 +1,120 @@ + + + + + + +
+
+
+
+
+ +
+
+
+
+ 勾选数据导出指定列,否则为全部 + + 导出 + +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/index-topnav.html b/ruoyi-admin/src/main/resources/templates/index-topnav.html index b30a9866..7d361330 100644 --- a/ruoyi-admin/src/main/resources/templates/index-topnav.html +++ b/ruoyi-admin/src/main/resources/templates/index-topnav.html @@ -123,6 +123,7 @@
  • 数据汇总
  • 组合表头
  • 表格导出
  • +
  • 导出选择列
  • 翻页记住选择
  • 跳转至指定页
  • 自定义查询参数
  • diff --git a/ruoyi-admin/src/main/resources/templates/index.html b/ruoyi-admin/src/main/resources/templates/index.html index 084dd9e4..7bb34e4f 100644 --- a/ruoyi-admin/src/main/resources/templates/index.html +++ b/ruoyi-admin/src/main/resources/templates/index.html @@ -104,6 +104,7 @@
  • 数据汇总
  • 组合表头
  • 表格导出
  • +
  • 导出选择列
  • 翻页记住选择
  • 跳转至指定页
  • 自定义查询参数