我正在查询数据库以根据输入字符串返回值列表;这些值列表显示在用户的搜索框中。问题是,我返回的列表显示为对象而不是名称列表。附上代码片段来说明我的观点
我的检索方法
public List<EmployeeDetails> getEmployeeByName(String employeeName) {
List<EmployeeDetails> list=new ArrayList<EmployeeDetails>();
Connection c=null;
String sql=("SELECT * FROM employee_table WHERE UPPER(employeeName) LIKE ? ORDER BY employeeName");
try{
c = ConnectionHelper.getConnection();
PreparedStatement ps=c.prepareStatement(sql);
ps.setString(1, "%" + employeeName.toUpperCase() + "%");
ResultSet rs=ps.executeQuery();
while(rs.next()){
list.add(new EmployeeDetails (rs.getInt("employeeid"),
rs.getString("employeeName"),
rs.getString("employeeAddress"),
rs.getString("employeeAge"),
rs.getString("nationality"),
rs.getString("salaryRate")));
}
}catch (SQLException e) {
e.printStackTrace();
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
} finally {
ConnectionHelper.close(c);
}
return **list**;
}
我打算只填充返回对象的名称,而不是原始封装对象的名称。我该怎么做?任何帮助/指针将不胜感激