public Object mapRow(ResultSet rs)throws SQLException;
}
3.环境类
public static List executeQuery(RowMapper rm,String sql,Object...params){
List list=new ArrayList();
try {
Connection con=CommonDao.getConnection();
PreparedStatement pstmt=con.prepareStatement(sql);
if(params!=null){
for(int i=0;i<params.length;i++){
pstmt.setObject((i+1), params[i]);
}
}
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
Object obj=rm.mapRow(rs);
list.add(obj);
}
CommonDao.closeAll(rs, pstmt, con);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
4具体策略类
这个在测试代码中客户根据自己想要返回的返回值类型定。