补充上一篇

private Field getFieldFromClass(Class<?> clazz, String propertyName, Class<?> propertyType) throws NoSuchFieldException {
		
		try {
			if (Boolean.class != propertyType && boolean.class != propertyType) {
				return clazz.getDeclaredField(propertyName);
			} else {
				String fieldName = "is" +String.valueOf(propertyName.charAt(0)).toUpperCase() + propertyName.substring(1);
				return clazz.getDeclaredField(fieldName);
			}
		} catch (NoSuchFieldException e) {
			Class<?> superClass = clazz.getSuperclass();
			if (superClass != null) {
				return getFieldFromClass(clazz.getSuperclass(), propertyName, propertyType);
			} else {
				throw e;
			}
		}
	}


你可能感兴趣的:(补充上一篇)