RowHandler的使用
实现一个filter,查询sex=1的所有记录。使用queryWithRowHandler()方法。
FilterRowHandler.java
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;}}
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));}