03-dbutils源码之BeanProcessor、RowProcessor、BasicRo...
在dbutils中, BeanProcessor 是一个很重要的类:将列和bean对象的属性进行匹配,将列的值赋予bean的对象。这个是使用了反射来进行的。 来看下类的outline: 从上图可以看出,有“创建对象”、“调用setter”、“获得类的属性描述符”等方法,还有一个最重要的方法mapColumnsToProperties(ResultSetMetaData,PropertyDescriptor),这个方法是将结果集和类的属性进行一个匹配。toBean是将一行记录转换成一个bean对象。toBeanList就是将多行记录变成bean对象的List集合。 下面看一下它的具体实现。 /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License