public class UserDAOImpl extends JdbcDaoSupport implements UserDAO {
/**
* 删除用户
*/
public void deleteUser(int id) {
String del_sql="delete from user where id=?";
this.getJdbcTemplate().update(del_sql, new Object[]{id});
}
/**
* 查找单个用户
*/
public User find(int id) {
String query_sql="select *from user where id=?";
this.getJdbcTemplate().queryForObject(query_sql, new Object[]{id}, userMapper);
return null;
}
/**
* 查找用户列表
*/
@SuppressWarnings("unchecked")
public List<User> findUserList() {
String sel_sql="select *from user";
return this.getJdbcTemplate().query(sel_sql,userMapper);
}
public boolean register(User user) {
return false;
}
/**
* 更新用户
*/
public void update(User user) {
String upd_sql="update user set name=?,password=? where id=?";
Object[] object=new Object[]{user.getName(),user.getPssword()};
this.getJdbcTemplate().update(upd_sql, object);
}
/**
* 映射实体(model)
*/
private ParameterizedRowMapper<User> userMapper=new ParameterizedRowMapper<User>(){
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
User user=new User();
user.setId(rs.getInt("id"));
user.setName(rs.getString("name"));
user.setPssword(rs.getString("password"));
return user;
}};
}