java 后台代码如何对数据进行封装
1、@RequestMapping("/loginAction.do") public String loginAction(String username,String password,HttpServletRequest request){ User user = null; try { user = userService.login(username.trim(), password.trim()); } catch (NameorPwdException e) { 侵捧 // TODO Auto-generated catch block e.printStackTrace(); } catch (NameorPwdEmptyException e) { // TODO Auto-generated catch block e.printStackTrace(); }

2、 HttpSession session = (HttpSession) request.getSession(); session.setAttribute("storePhone", user.getUserName()); session.setAttribute("user", user); session.setAttribute("code", ""); return "redirect:sell.do"; }

3、@RequestMapping("/sell.do") public String sell(Model model,String phone,HttpServletRequest request){ HttpSession session = request.getSession(); String storePhone = (String) session.getAttribute("storePhone"); if(session.getAttribute("user")==null || ""盆败.equals(session.getAttribute("user"))){ return "redirect:/login/login.do"; 粒宿悦}

1、public User login(String name,String password) throws NameorPwdException, NameorPwdEmptyException{ if(name==null||"".equals(name.trim())||"".equals(password.trim())){ throw new NameorPwdEmptyException("用户名或密码不能为空"); } User user = userDao.findByName(name); if(user==null){ throw new NameorPwdException("用户名不存在"); }

2、 if(user.getPassword().equalsIgnoreCase(password)){ return user; } System.out.println(name+"++"+password); throw new NameorPwdException("密码错误"); }

3、public List<Seed> findAllSeed(){ List <Seed> seeds = seedDao.findAll(); return seeds; }

4、对登录异常统一处理封装;将数据封装实体对象,或者map集合传递到前端
