/**
?* 使用JdbcTemplate返回单个对象
?* @param id
?* @return class
?*/?
??? public Classes findClasses(String id) {
??????? String sql = "select * from classes where id = ?";
??????? RowMapper mapper = new RowMapper() {
??????? public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
??????????????? Classes c = new Classes();
??????????????? c.setId(rs.getString("id"));
??????????????? c.setContent(rs.getString("content"));
??????????????? c.setUpid(rs.getString("upid"));
??????????????? c.setDistinction(rs.getString("distinction"));
??????????????? return c;
??????????? }
??????? };
??????? JdbcTemplate jdbcTemplate = new JdbcTemplate(this.getDataSource());
??????? return (Classes)jdbcTemplate.queryForObject(sql,new Object[]{id},mapper);
??? }
/**
?* 使用SimpleJdbcTemplate返回单个对象
?* @param id
?* @return class
?*/
??? public Classes findClasses2(String id) {
??????? String sql = "select * from classes where id = ?";
??????? ParameterizedRowMapper<classes> mapper = new ParameterizedRowMapper<classes>() {
??????????? // notice the return type with respect to Java 5 covariant return types
??????????? public Classes mapRow(ResultSet rs, int rowNum) throws SQLException {
??????????? ?Classes c = new Classes();
??????????????? c.setId(rs.getString("id"));
??????????????? c.setContent(rs.getString("content"));
??????????????? c.setUpid(rs.getString("upid"));
??????????????? c.setDistinction(rs.getString("distinction"));
??????????????? return c;
??????????? }
??????? };
??????? // again, normally this would be dependency injected of course...
??????? SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate(this.getDataSource());
??????? return simpleJdbcTemplate.queryForObject(sql, mapper, new Object[]{id});
??? }
/**
?* 使用JdbcTemplate返回多个对象
?* @return List
?*/?
??? @SuppressWarnings("static-access")
?public List findClasses3() {
??? ?
??????? String sql = "select * from classes ";
??????? ParameterizedRowMapper<list> mapper = new ParameterizedRowMapper<list>() {
??????????? public List mapRow(ResultSet rs, int rowNum) throws SQLException {
??????????? ?List<classes> res=new ArrayList<classes>();
??????????? ?do{
??????????? ??Classes c = new Classes();
???????????????? c.setId(rs.getString("id"));
???????????????? c.setContent(rs.getString("content"));
???????????????? c.setUpid(rs.getString("upid"));
???????????????? c.setDistinction(rs.getString("distinction"));
???????????????? res.add(c);
??????????? ?}
??????????? ?while(rs.next());
??????????? ?return res;
??????????? }
??????? };
??????? SimpleJdbcTemplate simpleJdbcTemplate = new SimpleJdbcTemplate(this.getDataSource());
??????? return (List)simpleJdbcTemplate.queryForObject(sql, mapper);
??? }