/** * 查询 用户名 密码 * * @param user */ public User selectUsPs(User user) { QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource()); String sql = "SELECT * FROM user WHERE username = ? AND password = ?"; try { User query = queryRunner.query( sql, new BeanHandler<User>(User.class), new Object[] {user.getUsername(), user.getPassword()}); return query; } catch (SQLException e) { e.printStackTrace(); return null; } }
public void insert(User user) { String userId = SessionUtils.getCurrentUserId(); if (StringUtils.isEmpty(userId)) { userId = user.getUserId(); } user.setPassword(MD5Utils.getMD5String(user.getPassword())); user.setDelflag("1"); Timestamp sysdate = new Timestamp(System.currentTimeMillis()); user.setCreateUser(userId); user.setCreateTime(sysdate); user.setUpdateUser(userId); user.setUpdateTime(sysdate); this.userDao.insert(user); }
@Override public boolean isValidUsernameAndPassword(String username, String password) { list = getAll(); if (username != null || password != null) { LOG.log(Level.INFO, " Login: "******" Password:"******" List size: " + list.size()); for (int i = 0; i < list.size(); i++) { User user = list.get(i); LOG.log(Level.INFO, " Users: " + user.toString()); if (user.getUsername().equals(username) && user.getPassword().equals(password)) { return true; } } } return false; }
/** 插入数据 */ public Integer insertUser(User user) { QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource()); try { String sql = "INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; Object param[] = { getID(), user.getUsername(), user.getPassword(), user.getSex(), user.getProfession(), user.getFavourite(), user.getNote(), user.getType() }; int update = queryRunner.update(sql, param); return update; } catch (SQLException e) { e.printStackTrace(); return null; } }
/** * 数据库操作 更新个人用户数据 * * @param user */ public void updateinfo(User user) { QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource()); String sql = "UPDATE user SET username = ?, password = ?, sex = ?, profession = ?, favourite = ?, note = ? WHERE id = ?;"; try { queryRunner.update( sql, new Object[] { user.getUsername(), user.getPassword(), user.getSex(), user.getProfession(), user.getFavourite(), user.getNote(), user.getId() }); } catch (SQLException e) { e.printStackTrace(); } }
public void testGetPassword() throws Exception { assertEquals("1234", u.getPassword()); }