我有一个名为employee 的对象,它有很长的属性列表,我正在从数据库中检索值并需要将它们放入employee 对象中,我正在执行以下操作,但是由于代码太长,我想知道是否有任何它的捷径。
Employee emp = new Employee();
try {
ps = con.prepareStatement("select * from Employee WHERE username = ?");
ps.setString(1, username);
ResultSet r = ps.executeQuery();
if (r.next()) {
// 12 lines to put values into employee object need to be shorter
emp.setID(r.getInt(1));
emp.setTitle(r.getString(2));
emp.setFname(r.getString(3));
emp.setLname(r.getString(4));
emp.setMobile(r.getString(5));
emp.setPhone(r.getString(6));
emp.setEmail(r.getString(7));
emp.setPosition(r.getString(8));
emp.setUsername(r.getString(9));
emp.setPassword(r.getString(10));
emp.setQuestion(r.getString(11));
emp.setAnswer(r.getString(12));
}
}.....