cn.hutool.db.handler.BeanHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.db.handler;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
/**
* Bean对象处理器,只处理第一条数据
*
* @param 处理对象类型
* @author loolly
*@since 3.1.0
*/
public class BeanHandler implements RsHandler{
private static final long serialVersionUID = -5491214744966544475L;
private final Class elementBeanType;
/**
* 创建一个 BeanHandler对象
*
* @param 处理对象类型
* @param beanType Bean类型
* @return BeanHandler对象
*/
public static BeanHandler create(Class beanType) {
return new BeanHandler<>(beanType);
}
public BeanHandler(Class beanType) {
this.elementBeanType = beanType;
}
@Override
public E handle(ResultSet rs) throws SQLException {
final ResultSetMetaData meta = rs.getMetaData();
final int columnCount = meta.getColumnCount();
return rs.next() ? HandleHelper.handleRow(columnCount, meta, rs, this.elementBeanType) : null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy