首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

commons.dbutils包地图ping时字段的映射有关问题

2012-12-20 
commons.dbutils包mapping时字段的映射问题!protected int[] mapColumnsToProperties(ResultSetMetaData r

commons.dbutils包mapping时字段的映射问题!

    protected int[] mapColumnsToProperties(ResultSetMetaData rsmd,            PropertyDescriptor[] props) throws SQLException {        int cols = rsmd.getColumnCount();        int columnToProperty[] = new int[cols + 1];        Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);        for (int col = 1; col <= cols; col++) {            String columnName = rsmd.getColumnLabel(col);            if (null == columnName || 0 == columnName.length()) {              columnName = rsmd.getColumnName(col);            }            for (int i = 0; i < props.length; i++) {                if (columnName.equalsIgnoreCase(props[i].getName())) {                    columnToProperty[col] = i;                    break;                }            }        }        return columnToProperty;    }

如上如果在数据库定义的字段中为下划线形式,而Pojo中是驼峰式。这样就会发生映不到对应字段。解决方案:1.修改commons.dbutils 关于BeanProcessor如上方法的源码getColumnnName时候在进行一次转化(替换掉下划线转为驼峰式),重新打包编译.2.使用数据库别名!

热点排行