org.springframework.util.ReflectionUtils.FieldFilter Java Examples

The following examples show how to use org.springframework.util.ReflectionUtils.FieldFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyBatisUtil.java    From phone with Apache License 2.0 6 votes vote down vote up
/**
 * 解析对象为Model
 * 自定义filter
 * @param obj
 * @param parseSuper 是否解析父类
 * @return
 */
public static List<Model> parseByObject(Object obj,boolean parseSuper,FieldFilter ff){
	List<Model> list = new ArrayList<>();
	if (obj==null) {
		return list;
	}
	//解析Field
	FieldCallback fc = new FieldCallback() {
		@Override
		public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
			if (ff != null && !ff.matches(field)) {
				return;
			}
			Model m = parseByField(obj, field);
			if (m!=null) {
				list.add(m);
			}
		}
	};
	if (parseSuper) {
		ReflectionUtil.doWithFields(obj.getClass(),fc);
	}else{
		ReflectionUtil.doWithLocalFields(obj.getClass(),fc);
	}
	return list;
}