SSM中的JS之文档批量导出

首先 jsp页面代码

//js部分

    <script type="text/javascript">
        function dao() {
            var id = "";
            var flag = "";
            var ids = document.getElementsByName("ids");
            for (var i = 0; i < ids.length; i++) {
                if (ids[i].checked == true) {
                    id += "," + ids[i].value;
                    flag++;
                }
            }
            id = id.substring(1);
            if (flag == 0) {
                alert("请选择要导出的选项");
                return false;
            }
            location.href = "userAction/daochu.action?id=" + id;
        }
    </script>

//表部分

<table align="center" border="1">
            <tr>
                <td>操作</td>
                <td>用户ID</td>
                <td>员工姓名</td>
                <td>所属部门</td>
                <td>职位</td>
                <td>员工薪资</td>
                <td>入职时间</td>
            </tr>
            <c:forEach items="${userlist}" var="userlist">
                <tr>
                    <td><input type="checkbox" value="${userlist.id}" name="ids"></td>
                    <td>${userlist.id}</td>
                    <td>${userlist.empname}</td>
                    <td>${userlist.department}</td>
                    <td>${userlist.position}</td>
                    <td>${userlist.salary}</td>
                    <td><fmt:formatDate value="${userlist.joinDate}" type="date"
                            pattern="yyyy-MM-dd" /></td>
                </tr>
                <tr>
                </tr>
            </c:forEach>
            <input type="button" value="批量导出" onclick="dao()" />
            <br/><br/><br/>
            <input type="button" value="批量删除" id="delete">
        </table>

(action层)

       //批量导出
        @RequestMapping("/daochu.action")
        public String daochu(String id){
            System.out.println(id);
            String[] s = id.split(",");
            for (String string : s) {
                List<User> list = userService.selectById(Integer.parseInt(string));
                for (User user : list) {
                    try {
                        PrintWriter printWriter = new PrintWriter(new FileOutputStream("D://test.txt",true),true);
                        printWriter.println(user.toString());
                        printWriter.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }

            return "success";

        }

(service层)

        @Override
    public List<User> selectById(int id) {
        return userMapper.selectById(id);
    }

(mapper层)

        //批量导出
    public List<User> selectById(int id);

(xml部分)

<!-- 批量导出 -->
    <select id="selectById" parameterType="java.lang.String" resultType="user">
       select * from employee where id = #{id}
    </select>

这就是JS的文本批量导出

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值