/** * 更新用户 * * @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); } }
/** * 查询用户数据的数量 * * @param user * @return */ public long getUserCount(User user) { StringBuilder sql = new StringBuilder(); sql.append(" select count(1) from USER_INFO WHERE 1=1 "); ParamInfo paramInfo = new ParamInfo(); if (!Utils.isEmpty(user.getName())) { sql.append(" AND name like ? "); paramInfo.setTypeAndData(Types.VARCHAR, "%" + user.getName() + "%"); } if (!Utils.isEmpty(user.getType())) { sql.append(" AND type = ? "); paramInfo.setTypeAndData(Types.CHAR, user.getType()); } if (!Utils.isEmpty(user.getStatus())) { sql.append(" AND status = ? "); paramInfo.setTypeAndData(Types.CHAR, user.getStatus()); } return userDao.getCount(sql.toString(), paramInfo); }