实体
public class Department {
private String departmentId;
private String departmentName;
private String departmentRemark;
/**
*
* create a instance Department.
*/
public Department(){
}
public Department(String departmentId, String departmentName,
String departmentRemark) {
super();
this.departmentId = departmentId;
this.departmentName = departmentName;
this.departmentRemark = departmentRemark;
}
public String getDepartmentId() {
return departmentId;
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getDepartmentRemark() {
return departmentRemark;
}
public void setDepartmentRemark(String departmentRemark) {
this.departmentRemark = departmentRemark;
}
}
------最佳解决方案--------------------
输出list是会出现那种结果啊,您下面的那些什么什么部是怎么打出来的啊。
------其他解决方案--------------------
大哥。。哪可以这样输出 遍历list啊
------其他解决方案--------------------
我错了,求轻喷
------其他解决方案--------------------
楼主什么问题?
------其他解决方案--------------------
实现方法:
public ArrayList<Department> findAllDepartment() {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ArrayList<Department> list =new ArrayList<Department>();
String sql="select * from asset_department order by department_id";
try {
conn=DB.getConn();
stmt=DB.getStatement(conn);
rs=DB.getResultSet(stmt, sql);
while(rs.next()){
Department department=new Department();
department.setDepartmentId(rs.getString("department_id"));
department.setDepartmentName(rs.getString("department_name"));
department.setDepartmentRemark(rs.getString("department_remark"));
list.add(department);
System.out.println(list);
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
DB.closeRs(rs);
DB.closeStmt(stmt);
DB.closeConn(conn);
}
System.out.println("ListSize为:"+list.size());
return list;
}
------其他解决方案--------------------
为什么打印出来的list是这个样子啊
也就是三个字段只打印出了一个departmentName,id和remark为什么没打印出来啊
------其他解决方案--------------------
我晕,System.out.println(list);你直接打印List对象怎么可能会出你要的效果。
要么你重写List的toString()方法,要么你老老实实的遍历List,一个对象一个对象的打印。
------其他解决方案--------------------
我错了,求轻喷