package cn.itcast.hys.dao;
import cn.itcast.hys.domain.PageBean;
import cn.itcast.hys.domain.User;
import cn.itcast.hys.utile.JDBCUtile;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
import java.util.Map;
public class UserDaoImp implements UserDao {
JdbcTemplate jt=new JdbcTemplate(JDBCUtile.getDs());
@Override
public User select(User u) {
try {
User user = jt.queryForObject("select * from user where username=? and password=?", new BeanPropertyRowMapper<User>(User.class), u.getUsername(), u.getPassword());
System.out.println(user);
return user;
} catch (DataAccessException e) {
return null;
}
}
public List<User> selectAll() {
List<User> user = jt.query("select * from user",new BeanPropertyRowMapper<User>(User.class));
return user;
}
public List selectname(String name) {
List<User> list = jt.query("select * from user where name=?", new BeanPropertyRowMapper<User>(User.class), name);
return list;
}
@Override
public void insert(User u) {
System.out.println(u);
jt.update("insert into user values (null ,?,?,?,?,?,?,null ,null )",u.getName(),u.getGender(),u.getAge(),u.getAddress(),u.getQq(),u.getEmail());
}
@Override
public void delete(int id) {
jt.update("delete from user where id=?",id);
}
@Override
public User selectid(int i) {
User user = jt.queryForObject("select * from user where id=?", new BeanPropertyRowMapper<User>(User.class), i);
return user;
}
@Override
public void update(User u) {
jt.update("update user set name=?,gender=?,age=?,address=?,qq=?,email=? where id=?",u.getName(),u.getGender(),u.getAge(),u.getAddress(),u.getQq(),u.getEmail(),u.getId());
}
@Override
public List<User> selectUserByPage(int currentPage, int rows) {
List<User> query = jt.query("select * from user limit ?,?", new BeanPropertyRowMapper<User>(User.class), currentPage, rows);
return query;
}
@Override
public int findTotalCount() {
int integer = jt.queryForObject("select count(*) from user", Integer.class);
return integer;
}
}
|
|