将字段转驼峰,获取对象中的属性值
// 获取对象中属性的值 public String getFieldValue(String attrName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { // 转驼峰 String standardField = getStandardField(attrName.toLowerCase()); String getField = "get" + standardField; return this.getClass().getMethod(getField).invoke(this).toString(); } // 获取驼峰字段 private String getStandardField(String field){ int index = field.indexOf("_"); if(index==-1){ return field.substring(0,1).toUpperCase() + field.substring(1); } String prefix = field.substring(0, index); String upperCase = field.substring(index, index + 2).replace("_","").toUpperCase(); String suffix = field.substring(index + 2 ); return getStandardField(prefix + upperCase + suffix); }