@Test public void queryBrands() throws Exception { List<Brand> brands = brandDao.queryBrands(1); for (Brand brand : brands) { System.out.println(brand.getName()); } }
@Override public List<Brand> queryBrands(int typeId) { String sql = "SELECT * FROM brand WHERE type_id = ?"; SqlRowSet row = template.queryForRowSet(sql, new Object[]{typeId}); List<Brand> list = new ArrayList<>(); Brand brand = null; while (row.next()) { brand = new Brand(); brand.setTypeId(row.getInt("type_id")); brand.setName(row.getString("name")); brand.setBrandId(row.getInt("brand_id")); brand.setCommon(row.getInt("common")); list.add(brand); } return list; }
BrandDaoImpl implements BrandDao { @Override public List<Brand> queryBrands(int typeId) { String sql = "SELECT * FROM brand WHERE type_id = ?"; SqlRowSet row = template.queryForRowSet(sql, new Object[]{typeId}); List<Brand> list = new ArrayList<>(); Brand brand = null; while (row.next()) { brand = new Brand(); brand.setTypeId(row.getInt("type_id")); brand.setName(row.getString("name")); brand.setBrandId(row.getInt("brand_id")); brand.setCommon(row.getInt("common")); list.add(brand); } return list; } }
BrandDaoImpl implements BrandDao { @Override public List<Brand> queryBrands(int typeId) { String sql = "SELECT * FROM brand WHERE type_id = ?"; SqlRowSet row = template.queryForRowSet(sql, new Object[]{typeId}); List<Brand> list = new ArrayList<>(); Brand brand = null; while (row.next()) { brand = new Brand(); brand.setTypeId(row.getInt("type_id")); brand.setName(row.getString("name")); brand.setBrandId(row.getInt("brand_id")); brand.setCommon(row.getInt("common")); list.add(brand); } return list; }  }
BrandDaoImpl implements BrandDao { @Override public List<Brand> queryBrands(int typeId) { String sql = "SELECT * FROM brand WHERE type_id = ?"; SqlRowSet row = template.queryForRowSet(sql, new Object[]{typeId}); List<Brand> list = new ArrayList<>(); Brand brand = null; while (row.next()) { brand = new Brand(); brand.setTypeId(row.getInt("type_id")); brand.setName(row.getString("name")); brand.setBrandId(row.getInt("brand_id")); brand.setCommon(row.getInt("common")); list.add(brand); } return list; }  JdbcTemplate getTemplate(); void setTemplate(JdbcTemplate template); @Override void insert(Brand brand); @Override void insert(List<Brand> brands); @Override List<Brand> queryBrands(int typeId); }
BrandDaoImpl implements BrandDao { @Override public List<Brand> queryBrands(int typeId) { String sql = "SELECT * FROM brand WHERE type_id = ?"; SqlRowSet row = template.queryForRowSet(sql, new Object[]{typeId}); List<Brand> list = new ArrayList<>(); Brand brand = null; while (row.next()) { brand = new Brand(); brand.setTypeId(row.getInt("type_id")); brand.setName(row.getString("name")); brand.setBrandId(row.getInt("brand_id")); brand.setCommon(row.getInt("common")); list.add(brand); } return list; }  JdbcTemplate getTemplate(); void setTemplate(JdbcTemplate template); @Override void insert(Brand brand); @Override void insert(List<Brand> brands); @Override List<Brand> queryBrands(int typeId);  }