/**
* 根据id查询
* @param clasz
* @param id
* @return
*/
public static Object get(Class<?> clasz, int id) {
Connection con = null;
Object obj = null;
try {
con = getConnection();
@SuppressWarnings({ "unchecked", "rawtypes" })
List<?>result = (List<?>) runner.query(con,
"select * from " + clasz.getSimpleName().toLowerCase() + " where id=" + id,
new BeanListHandler(clasz));
if (result!=null && result.size()>0) {
obj = result.get(0);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (con!=null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return obj;
}
} |