实现一个filter,查询sex=1的所有记录。使用queryWithRowHandler()方法。
[color=red]FilterRowHandler.java[/color]
UserDaoImpl.java
[color=red]FilterRowHandler.java[/color]
package com.cs;
import java.util.ArrayList;
import java.util.List;
import com.ibatis.sqlmap.client.event.RowHandler;
public class FilterRowHandler implements RowHandler {
private List<User> list = new ArrayList<User>();
public void handleRow(Object obj) {
User user = (User)obj;
if(user.getSex()==1) {
list.add(user);
}
}
public List<User> getList() {
return list;
}
}
UserDaoImpl.java
FilterRowHandler rh = new FilterRowHandler();
try {
sqlmapper.queryWithRowHandler("selectAllUser", rh);
} catch (SQLException e) {
e.printStackTrace();
}
List<User> list = rh.getList();
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}