@Override publicintupdate(Author author){ return jdbcTemplate.update("update t_author set real_name = ?, nick_name = ? where id = ?", new Object[]{author.getRealName(), author.getNickName(), author.getId()}); }
@Override publicintdelete(Long id){ return jdbcTemplate.update("delete from t_author where id = ?", id); }
@Override public Author findAuthor(Long id){ List<Author> list = jdbcTemplate.query("select * from t_author where id = ?", new Object[]{id}, new BeanPropertyRowMapper(Author.class)); if(null != list && list.size()>0){ Author auhtor = list.get(0); return auhtor; }else{ returnnull; } } @Override public List<Author> findAuthorList(){ List<Author> list = jdbcTemplate.query("select * from t_author", new Object[]{}, new BeanPropertyRowMapper<Author>(Author.class)); return list; } }
试下单元测试
1 2 3 4
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(WpspringbootApplication.class) public class JdbcTest { }