BeanHandler,把一条sql的记录封装到javabean中
public Customer findById(String id) {
QueryRunner runner = new QueryRunner(());
try {
return ("select * from t_customer where id = ?", new BeanHandler<Customer>() ,id);
} catch (SQLException e) {
();
throw new RuntimeException("通过ID查询失败");
}
BeanListHandler,把一条sql的记录封装到javabean中,把多个javabean放入List集合当中
public List<Customer> findAll(){
//DButils的方法,创建一个QueryRunner类,传入的参数是c3p0连接池对象
QueryRunner runner = new QueryRunner(());
try {
//返回一个List
return ("select * from t_customer", new BeanListHandler<Customer>());
} catch (SQLException e) {
();
throw new RuntimeException("查询全部结果失败");
}
}