@Test public void testFindByLastname() throws Exception { final String lastName = "Smith"; final List<Person> smiths = createListOfPeopleWithLastname(lastName); JdbcTemplate template = createMock(JdbcTemplate.class); template.query( eq("SELECT * FROM employee WHERE last_name = ?"), aryEq(new Object[] { lastName }), isA(PersonRowMapper.class)); expectLastCall().andReturn(smiths); replay(template); JdbcTemplatePersonDao dao = new JdbcTemplatePersonDao(); dao.setJdbcTemplate(template); assertEquals(smiths, dao.findByLastname(lastName)); verify(template); }
@SuppressWarnings("unchecked") public List<Person> findByLastName(String lastName) { String sql = "SELECT * FROM employee WHERE last_name = ?"; Object[] args = { lastName }; RowMapper mapper = new PersonRowMapper(); return getJdbcTemplate().query(sql, args, mapper); }
JdbcTemplatePersonDao extends JdbcDaoSupport implements
        PersonDao { @SuppressWarnings("unchecked") public List<Person> findByLastName(String lastName) { String sql = "SELECT * FROM employee WHERE last_name = ?"; Object[] args = { lastName }; RowMapper mapper = new PersonRowMapper(); return getJdbcTemplate().query(sql, args, mapper); } }
JdbcTemplatePersonDao extends JdbcDaoSupport implements
        PersonDao { @SuppressWarnings("unchecked") public List<Person> findByLastName(String lastName) { String sql = "SELECT * FROM employee WHERE last_name = ?"; Object[] args = { lastName }; RowMapper mapper = new PersonRowMapper(); return getJdbcTemplate().query(sql, args, mapper); }  }
JdbcTemplatePersonDao extends JdbcDaoSupport implements
        PersonDao { @SuppressWarnings("unchecked") public List<Person> findByLastName(String lastName) { String sql = "SELECT * FROM employee WHERE last_name = ?"; Object[] args = { lastName }; RowMapper mapper = new PersonRowMapper(); return getJdbcTemplate().query(sql, args, mapper); }  @SuppressWarnings("unchecked") List<Person> findAll(); @SuppressWarnings("unchecked") List<Person> findByLastName(String lastName); @SuppressWarnings("unchecked") List<Person> findByLastname(String lastname); void save(final Person person); Person find(Long id); }
JdbcTemplatePersonDao extends JdbcDaoSupport implements
        PersonDao { @SuppressWarnings("unchecked") public List<Person> findByLastName(String lastName) { String sql = "SELECT * FROM employee WHERE last_name = ?"; Object[] args = { lastName }; RowMapper mapper = new PersonRowMapper(); return getJdbcTemplate().query(sql, args, mapper); }  @SuppressWarnings("unchecked") List<Person> findAll(); @SuppressWarnings("unchecked") List<Person> findByLastName(String lastName); @SuppressWarnings("unchecked") List<Person> findByLastname(String lastname); void save(final Person person); Person find(Long id);  }