上一部分代码:
publicstaticListgetForList(Classclazz,Stringsql,
Object...args){
Listlist=newArrayList();
Connectionconn=null;
PreparedStatementpreparedStatement=null;
ResultSetresultSet=null;
try{
conn=JDBCTools.getConnection();
preparedStatement=(PreparedStatement)conn.prepareStatement(sql);
for(inti=0;imap=null;
List>listMap=newArrayList();
while(resultSet.next()){
map=newHashMap();
for(inti=0;i0){
for(Mapmap1:listMap){
bean=clazz.newInstance();
for(Map.Entryentry:map1.entrySet()){
Stringkey=entry.getKey();
Objectvalue=entry.getValue();
System.out.println(key);//debug
System.out.println(value);//debug
BeanUtils.setProperty(bean,key,value);//问题出在这,感觉bean没被赋值。
}
list.add(bean);
}
}
}catch(Exceptione){
e.printStackTrace();
}finally{
JDBCTools.release(resultSet,preparedStatement,conn);
}
returnlist;
}
//测试类
@Test
publicvoidtestGetForList2(){
Stringsql="SELECTID,Name,Age,Emailfromstudents";
Liststudents=DAO.getForList(Student.class,sql);
System.out.println(students);
}
//结果输出:从打印结果可以看出,两条debug的输出是有数据的,怎么紧接着的BeanUtils.setProperty(bean,key,value),没有对bean对象赋值呢?求大神解答。
Email
[email protected]
ID
1
Age
18
Name
zhang,sanfeng
Email
[email protected]
ID
2
Age
19
Name
li,si
Email
[email protected]
ID
3
Age
20
Name
Wang,wu
Email
[email protected]
ID
4
Age
21
Name
Zhao,liu
Email
[email protected]
ID
6
Age
22
Name
Wang,yuan
Email
[email protected]
ID
7
Age
20
Name
wang,mazi
[Student[id=0,name=null,age=0,email=null]
,Student[id=0,name=null,age=0,email=null]
,Student[id=0,name=null,age=0,email=null]
,Student[id=0,name=null,age=0,email=null]
,Student[id=0,name=null,age=0,email=null]
,Student[id=0,name=null,age=0,email=null]
]
分 -->
|