예제 #1
0
 // 完整的参数项为:@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";
   }
 }
예제 #2
0
 /**
  * 用户编辑
  *
  * @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";
 }