Exemplo n.º 1
0
  @RequestMapping(method = RequestMethod.GET)
  @ResponseBody
  public Object getUser(
      @RequestParam(value = "userId", required = false) String userId,
      @RequestParam(value = "userName", required = false) String userName,
      @RequestParam(value = "department", required = false) String department) {
    try {
      if (userId != null) {
        List<User> users = new ArrayList<User>(1);
        users.add(userService.selectUserByUserId(userId));
        return users;
      } else if (userName != null) {
        return userService.selectUserByUserName(userName);
      } else if (department != null) {
        return userService.selectUserByDepartment(department);
      } else {
        return userService.selectUser();
      }
    } catch (Exception e) {
      logger.error("can't select user", e);

      Map<String, String> result = new HashMap<String, String>();
      result.put("errorCode", "500");
      result.put("errorMessage", "This api need to collect condition for search.");
      return result;
    }
  }
Exemplo n.º 2
0
  @RequestMapping(method = RequestMethod.DELETE)
  @ResponseBody
  public Map<String, String> deletetUser(@RequestBody User user) {
    if (StringUtils.isEmpty(user.getUserId())) {
      Map<String, String> result = new HashMap<String, String>();
      result.put("errorCode", "500");
      result.put("errorMessage", "there is not userId in params to delete user");
      return result;
    }

    userService.deleteUser(user);

    Map<String, String> result = new HashMap<String, String>();
    result.put("result", "SUCCESS");
    return result;
  }
Exemplo n.º 3
0
  @RequestMapping(method = RequestMethod.POST)
  @ResponseBody
  public Map<String, String> insertUser(@RequestBody User user) {

    if (StringUtils.isEmpty(user.getUserId()) || StringUtils.isEmpty(user.getName())) {
      Map<String, String> result = new HashMap<String, String>();
      result.put("errorCode", "500");
      result.put(
          "errorMessage", "there is not userId or name in params to creating user infomation");
      return result;
    }

    userService.insertUser(user);

    Map<String, String> result = new HashMap<String, String>();
    result.put("result", "SUCCESS");
    return result;
  }