List<T> findAll(PK start,PK count);
/*根据主键查询实体*/
T findById(PK id);
}
CustomerDao接口:
package cn.csdn.customer.dao;
import cn.csdn.customer.domain.Customer;
public interface CustomerDao extends Dao<Customer,Integer> {
int getCount();
}
CustomerDaoImpl接口实例类:
package cn.csdn.customer.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import cn.csdn.customer.domain.Customer;
import cn.csdn.customer.util.JdbcUtil;
public class CustomerDaoImpl implements CustomerDao {
/* 封装数据库操作的对象 */
private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;
public boolean insert(Customer entity) {
/* 第一步:声明返回值变量 */
boolean flag = false;
try {
/* 第二步:获取连接对象 */
conn = JdbcUtil.getConn();
/* 第三步:定义sql语句 */
String sql = "insert into customer(name,gender,birthday,cellphone,Email,preference,type,Description)values(?,?,?,?,?,?,?,?)";
/* 第四步:根据sql语句获取预处理对象 */
pstmt = conn.prepareStatement(sql);
/* 第五步:为占位符赋值 */
int index = 1;
pstmt.setObject(index++, entity.getName());
pstmt.setObject(index++, entity.getGender());
pstmt.setObject(index++, entity.getBirthday());
pstmt.setObject(index++, entity.getCellphone());