/** * 修改用户 * * @param request */ @RequestMapping(value = "/editUser/{id}", method = RequestMethod.GET) public String editUser(@PathVariable("id") int id, Model model) { Users user = userService.selectById(id); System.out.println(id); System.out.println(user.getPhone()); model.addAttribute("user", user); return "editUser"; }
/** * 用户登录 * * @param name * @param password * @param session * @param model * @return */ @RequestMapping(value = "/login", method = RequestMethod.POST) public String loginCheck( @RequestParam(value = "name") String name, @RequestParam(value = "password") String password, HttpSession session, Model model) { String view = null; Users user = userService.loging(name, password); System.out.println("用户登录:" + name); session.setAttribute("uname", name); if (user.getUlevel() == 2) { view = "manager"; // 经理 } else if (user.getUlevel() == 1) { view = "DianZhang"; // 店长 } else if (user.getUlevel() == 0) { view = "salesman"; // 业务员 } return "Index"; }
// 完整的参数项为:@RequestMapping(value="",method = // {"",""},headers={},params={"",""}),各参数说明如下: // value :String[] 设置访问地址 // method: RequestMethod[]设置访问方式,字符数组,查看RequestMethod // 类,包括GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE,常用 // RequestMethod.GET,RequestMethod.POST // headers:String[] headers一般结合method = RequestMethod.POST使用 // params: String[] 访问参数设置,字符数组 例如:userId=id @RequestMapping(value = "/addUser", method = RequestMethod.POST) public String addUs( // 在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"), // 另外一种是用注解@RequestParam直接获取。 @RequestParam(value = "name") String name, @RequestParam(value = "password") String password, @RequestParam(value = "phone") String phone, @RequestParam(value = "idcard") String idcard, @RequestParam(value = "store_id") int storeid, @RequestParam(value = "state") int state, @RequestParam(value = "ulevel") int ulevel, Users user, Model moudel) throws IOException { System.out.println( name + ":" + password + ":" + phone + ":" + idcard + ":" + state + ":" + ulevel); user.setName(name); user.setPassword(password); user.setPhone(phone); user.setIdcard(idcard); user.setState(state); user.setUlevel(ulevel); int row = userService.addUser(user); if (row >= 1) { return "redirect:/selectAll"; } else { return "error"; } }
/** * 用户编辑 * * @param request * @param user * @return */ @RequestMapping(value = "/editUser/editUs", method = RequestMethod.POST) public String editUs(HttpServletRequest request, Users user) { System.out.println(">>>>>>>>>>>>>>>>"); user.setName(request.getParameter("name")); user.setPhone(request.getParameter("phone")); user.setIdcard(request.getParameter("idcard")); user.setStoreid(request.getParameter("storeid")); user.setState(Integer.parseInt(request.getParameter("state"))); user.setUlevel(Integer.parseInt(request.getParameter("ulevel"))); userService.editUser(user); return "redirect:/selectAll"; }