Exemplo n.º 1
0
  /**
   * 更新用户
   *
   * @param user
   * @return
   */
  public void updateUser(User user) {
    StringBuilder sql = new StringBuilder();
    sql.append("update USER_INFO set ");
    ParamInfo paramInfo = new ParamInfo();
    if (!Utils.isEmpty(user.getName())) {
      sql.append("name=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getName());
    }

    if (!Utils.isEmpty(user.getPhone())) {
      sql.append("phone=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getPhone());
    }

    if (!Utils.isEmpty(user.getNickname())) {
      sql.append("nickname=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getNickname());
    }

    if (!Utils.isEmpty(user.getSchoolId())) {
      sql.append("schoolId=?,");
      paramInfo.setTypeAndData(Types.BIGINT, user.getSchoolId());
    }

    if (!Utils.isEmpty(user.getMajor())) {
      sql.append("major=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getMajor());
    }

    if (!Utils.isEmpty(user.getGrade())) {
      sql.append("grade=?,");
      paramInfo.setTypeAndData(Types.CHAR, user.getGrade());
    }

    if (!Utils.isEmpty(user.getUrl())) {
      sql.append("url=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getUrl());
    }

    if (!Utils.isEmpty(user.getBackground_url())) {
      sql.append("background_url=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getBackground_url());
    }

    if (!Utils.isEmpty(user.getIndustry())) {
      sql.append("industry=?,");
      paramInfo.setTypeAndData(Types.VARCHAR, user.getIndustry());
    }

    if (sql.toString().endsWith(",")) {
      sql.replace(sql.length() - 1, sql.length(), "");
      sql.append(" where id=?");
      paramInfo.setTypeAndData(Types.BIGINT, user.getId());

      userDao.updateRecord(sql.toString(), paramInfo);
    }
  }
Exemplo n.º 2
0
 /**
  * 判断用户是否存在
  *
  * @param user
  * @return
  */
 public boolean isExistUser(User user) {
   StringBuilder sql = new StringBuilder();
   sql.append(" select 1 from USER_INFO WHERE phone=? ");
   ParamInfo paramInfo = new ParamInfo();
   paramInfo.setTypeAndData(Types.VARCHAR, user.getPhone());
   // paramInfo.setTypeAndData(Types.CHAR, user.getType());
   if (!Utils.isEmpty(user.getId())) {
     sql.append("and id <> ?");
     paramInfo.setTypeAndData(Types.BIGINT, user.getId());
   }
   List<User> l = userDao.getRecords(sql.toString(), paramInfo, User.class);
   if (l != null && l.size() > 0) return true;
   return false;
 }