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.使用数据库别名!