All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.penglecode.common.mybatis.EscapeResultHandler Maven / Gradle / Ivy

Go to download

commons is a little java tool to make your development easier in your work.

The newest version!
package com.penglecode.common.mybatis;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;

/**
 * 用于对查询结果集的每行数据部分字段进行转义的ResultHandler
 * 
 * @param 
 * @author	  	pengpeng
 * @date	  	2014年8月1日 下午3:54:19
 * @version  	1.0
 */
@SuppressWarnings("unchecked")
public class EscapeResultHandler implements ResultHandler {
	
	private final List list;

	private EscapeFilter escapeFilter;
	
	public EscapeResultHandler() {
		list = new ArrayList();
	}
	
	public EscapeResultHandler(EscapeFilter escapeFilter) {
		this();
		this.escapeFilter = escapeFilter;
	}

	public EscapeResultHandler(ObjectFactory objectFactory) {
		list = objectFactory.create(List.class);
	}

	
	public void handleResult(ResultContext context) {
		T element = (T) context.getResultObject();
		try {
			list.add(element);
		} finally {
			if(escapeFilter != null){
				escapeFilter.doEscapeFilter(element);
			}
		}
	}

	public List getResultList() {
		return list;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy