⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rolegroupaction.java

📁 hibernate应用测试,初学hibernate 的会员可以看看.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                ActionError actionError = new ActionError(
                        "errors.generally.failed", e.getMessage());
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
            }
            target = "groupSetRoleItem";
        } else if (flag.equals("showAccount")) { //跳转到当前组账号显示页面
            String groupIdStr = request.getParameter("groupId");
            try {
                int groupId = new Integer(groupIdStr).intValue();
                List theTeamAcount = AcountTableDAO.
                                     selectAccountAndGroupByGroupId(groupId);
                RoleGroup roleGroup = RoleGroupDAO.selectRoleGroupBygroupId(
                        groupId);
                List allRoleGroup = RoleGroupDAO.selectAllRoleGroup();
                request.setAttribute("theTeamAcount", theTeamAcount);
                request.setAttribute("allRoleGroup", allRoleGroup);
                request.setAttribute("roleGroup", roleGroup);
                target = "editAInTeam";
            } catch (Exception e) {
                e.printStackTrace();
                target = "";
            }
        } else if (flag.equals("forAddAcount")) { //跳转到为组添加账号
            return new AccountAction().execute(mapping, form, request, response);
        } else if (flag.equals("addAcountToTeam")) { //向当前组中添加账号
            String[] arryAcountIdStr = request.getParameterValues("checkbox");
            String groupIdStr = request.getParameter("groupId");
            if (arryAcountIdStr == null || arryAcountIdStr.length == 0 ||
                groupIdStr == null || groupIdStr.trim().equals("")) {
                ActionError actionError = new ActionError(
                        "errors.generally.failed", "无效的操作");
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
                return mapping.findForward("forTeamAAcount");
            }
            try {
                //将字符串的账号ID转换为整型
                int[] arryAcountId = new int[arryAcountIdStr.length];
                for (int i = 0; i < arryAcountId.length; i++) {
                    arryAcountId[i] = Integer.parseInt(arryAcountIdStr[i]);
                }
                int groupId = Integer.parseInt(groupIdStr);
                AcountGroupDAO.startTransation();
                int lastId = AcountGroupDAO.getLastId();
                //将账逐个添加进组,账号已在组中的不再添加
                for (int j = 0; j < arryAcountId.length; j++) {
                    AcountGroup tmp = new AcountGroup();
                    tmp.setAcountId(arryAcountId[j]);
                    tmp.setGroupId(groupId);
                    tmp.setSelfId(lastId + j + 1);
                    //判断账号是否已在组中
                    if (AcountGroupDAO.selectIsAcountInGroup(tmp))
                        continue; //若账号已在组中则不作操作
                    AcountGroupDAO.insertAcountGroup(tmp); //将账号添加进当前组
                    lastId = AcountGroupDAO.getLastId();
                }
                AcountGroupDAO.commit();
                //添加成功后,页面跳到当前组界面
                List theTeamAcount = AcountTableDAO.
                                     selectAccountAndGroupByGroupId(groupId);
                RoleGroup roleGroup = RoleGroupDAO.selectRoleGroupBygroupId(
                        groupId);
                List allRoleGroup = RoleGroupDAO.selectAllRoleGroup();
                request.setAttribute("theTeamAcount", theTeamAcount);
                request.setAttribute("allRoleGroup", allRoleGroup);
                request.setAttribute("roleGroup", roleGroup);
                target = "editAInTeam";
            } catch (Exception e) {
                e.printStackTrace();
                ActionError actionError = new ActionError(
                        "errors.generally.failed", e.toString());
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
                AcountGroupDAO.rollback();
                return new AccountAction().execute(mapping, form, request,
                        response);
            }
        } else if (flag.equals("getOut")) {
            String[] arryAcountGroupIdStr = request.getParameterValues(
                    "checkbox");
            String groupIdStr = request.getParameter("groupId");
            if (arryAcountGroupIdStr == null ||
                arryAcountGroupIdStr.length == 0) {
                ActionError actionError = new ActionError(
                        "errors.generally.failed", "无效的操作");
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);

                return mapping.findForward("");
            }
            int groupId = -1;
            try {
                int tmp = -1;
                groupId = Integer.parseInt(groupIdStr);
                AcountGroupDAO.startTransation();
                for (int i = 0; i < arryAcountGroupIdStr.length; i++) {
                    tmp = Integer.parseInt(
                            arryAcountGroupIdStr[i]);
                    if (tmp < 1)throw new Exception("参数错误码!");
                    AcountGroupDAO.deleteAcountGroupByselfId(tmp);
                }
                AcountGroupDAO.commit();
                ActionError actionError = new ActionError(
                        "errors.generally.succese");
                actionErrors.add("addGroupSuccese", actionError);
                saveErrors(request, actionErrors);

            } catch (Exception e) {
                e.printStackTrace();
                ActionError actionError = new ActionError(
                        "errors.generally.failed", e.toString());
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
                AcountGroupDAO.rollback();
            }
            List theTeamAcount = AcountTableDAO.
                                 selectAccountAndGroupByGroupId(groupId);
            RoleGroup roleGroup = RoleGroupDAO.selectRoleGroupBygroupId(
                    groupId);
            List allRoleGroup = RoleGroupDAO.selectAllRoleGroup();
            request.setAttribute("theTeamAcount", theTeamAcount);
            request.setAttribute("allRoleGroup", allRoleGroup);
            request.setAttribute("roleGroup", roleGroup);
            target = "editAInTeam";
        } else if (flag.equals("getToOther")) {//将账号从当前组移到选定组
            String[] arryAcountGroupIdStr = request.getParameterValues(
                    "checkbox");
            String groupIdStr2 = request.getParameter("groupId2");
            String groupIdStr = request.getParameter("groupId");
            if (arryAcountGroupIdStr == null || groupIdStr2 == null)return
                    mapping.findForward("");

            int groupId2 = -1;
            int groupId = -1;
            try {
                groupId2 = Integer.parseInt(groupIdStr2);
                groupId = Integer.parseInt(groupIdStr);
                for (int i = 0; i < arryAcountGroupIdStr.length; i++) {
                    int tmp = Integer.parseInt(arryAcountGroupIdStr[i]);
                    AcountGroup acountGroup = new AcountGroup();
                    acountGroup.setGroupId(groupId2);
                    acountGroup.setSelfId(tmp);
                    AcountGroupDAO.updateGroupIdByAcountGroupId(acountGroup);
                }
                ActionError actionError = new ActionError(
                        "errors.generally.succese");
                actionErrors.add("addGroupSuccese", actionError);
                saveErrors(request, actionErrors);
            } catch (Exception e) {
                e.printStackTrace();
                ActionError actionError = new ActionError(
                        "errors.generally.failed", e.toString());
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
            }
            List theTeamAcount = AcountTableDAO.
                                 selectAccountAndGroupByGroupId(groupId);
            RoleGroup roleGroup = RoleGroupDAO.selectRoleGroupBygroupId(
                    groupId);
            List allRoleGroup = RoleGroupDAO.selectAllRoleGroup();
            request.setAttribute("theTeamAcount", theTeamAcount);
            request.setAttribute("allRoleGroup", allRoleGroup);
            request.setAttribute("roleGroup", roleGroup);
            target = "editAInTeam";
        }
        return mapping.findForward(target);
    }

    //初始化并获得分页
    private Page initPage(HttpServletRequest request) {
        String currentPageStr = request.getParameter("currentPage");
        String queryStr = QueryStrCreator.create("roleGroup", request);
        int currentPage = 1; //当前页码
        int size = 20; //每页的记录数

        try { //防止从地址栏直接输入非法页码
            if (currentPageStr != null) currentPage = new Integer(
                    currentPageStr).intValue();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //处理分页
        //会话中是否已有分页生成工具
        PageTool pageTool = null;
        HttpSession session = request.getSession();
        pageTool = (PageTool) session.getAttribute("roleGroupPageTool"); //有,则直接拿来用
        if (pageTool == null) { //没有,则新建,并放进会话中,以备下次用
            pageTool = PageToolBuilder.builder(new RoleGroupDAO());
            session.setAttribute("roleGroupPageTool", pageTool);
        }
        //由分页工具生成分页
        Page page = null;
        try {
            String flag = request.getParameter("flag");
            if (flag.equals("query")) //查询时的分页
                page = pageTool.createPage(currentPage, size, queryStr);
            else //其它非查询的分页
                page = pageTool.createPage(currentPage, size);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        //将分页放进请求中,分发到下一个页面显示
        request.setAttribute("allRoleGroupPage", page);
        return page;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -