public class Employee { private int id; private String name; private double salary; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } public Employee(int id, String name, double salary) { super(); this.id = id; this.name = name; this.salary = salary; } @Override public String toString() { return "Employee [id=" + id + ", name=" + name + ", salary=" + salary + ", getId()=" + getId() + ", getName()=" + getName() + ", getSalary()=" + getSalary() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]"; } }
import java.util.List; import javax.sql.DataSource; import org.springframework.jdbc.core.JdbcTemplate; public class EmployeeDao { private final JdbcTemplate jdbcTemplate; public EmployeeDao(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } public List<Employee> findEmployes() { return jdbcTemplate.query("select id,name ,salary from Employee", new Object[] {}, (rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("name"), rs.getDouble("salary"))); } }