您的位置:首页 > 编程语言 > Java开发

springMVC中controller之前执行的方法

2016-07-14 16:32 453 查看
     @ModelAttribute()  

     public void getSessionUser() throws IOException, ServletException {

         HttpSession session = getSession();

         if (getLoginInfoFromSession()==null) {

             session.setMaxInactiveInterval(60*60);

             HttpServletRequest request = getRequest();

             String userId = request.getParameter("userId");

             String roleType = request.getParameter("roleType");

             if(userId==null||roleType==null){

                 request.getRequestDispatcher(request.getContextPath() + "/pages/error/500.html").forward(request, getResponse());

//                 getResponse().sendRedirect(request.getContextPath() + "/pages/error/500.html");

                 return;

             }

             List<AdminUser> adminUserList = adminUserService.getListByProperty("loginId",userId);

            

                LoginInfo loginInfo = new LoginInfo();

                AdminUser adminUser = adminUserList.get(0);

                if(adminUser.getSupplier()!=null&&AdminUser.ROLE_TYPE_SUPPLIER.equals(roleType)){

                    loginInfo.setSupplierId(adminUser.getSupplier().getId());

                    loginInfo.setSupplierName(adminUser.getSupplier().getSupplierName());

                }

                loginInfo.setRoleType(roleType);

                loginInfo.setAdminUser(adminUser);

                session.setAttribute(SESSION_LOGIN_INFO, loginInfo);

         }

     } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: