时间:2021-07-01 10:21:17 帮助过:20人阅读
public class AdminDao extends BaseDao {
// 删除
public void delete(int id) {
String sql = "delete from admin where id=?";
Object[] paramsValue = {id};
super.update(sql, paramsValue);
}
// 插入
public void insert(Admin admin) {
String sql = "insert into admin (userName,pwd) values (?,?)";
Object[] paramsValue = {admin.getUserName(),admin.getPwd()};
super.update(sql, paramsValue);
}
// 查询全部
public List<Admin> getAll(){
String sql = "select * from admin";
List<Admin> list = super.query(sql, null, Admin.class);
return list;
}
// 根据条件查询(主键)
public Admin findById(int id){
String sql = "select * from admin where id=?";
List<Admin> list = super.query(sql, new Object[]{id}, Admin.class);
return (list!=null&&list.size()>0) ? list.get(0) : null;
}
}
/**
* 1. bean类设计
* @author Charlie.chen
*
*/
public class Admin {
private int id;
private String userName;
private String pwd;
private int age;
private Date birth;
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "Admin [age=" + age + ", birth=" + birth + ", id=" + id
+ ", pwd=" + pwd + ", userName=" + userName + "]";
}
}
Java通过JDBC 进行Dao层的封装
标签:获取 lis size bean array 方法 详细介绍 通过 介绍