방금 Method Reflection API를 사용하여 하나의 일반적인 방법을 만들었습니다. 이 메서드에서는 미립자 메서드 (getter 메서드/setter 메서드) 값을 얻으려고하지만이 작업을 수행하는 방법을 모른다. 저는 Abel이 Method Reflection API를 사용하여 모든 메소드 이름을 가져 왔지만 Abel은이 메소드의 가치를 얻지 못했습니다. 그러니 제발 도와주세요.리플렉션을 사용하여 POJO에서 가치를 얻는 방법?
여기내 코드는 ......
/*
로 propertyNames 목록은 두 개의 레코드를 포함합니다. */
public <T>void fillList(List<String> propertyNames , T clas){
try{
for(Object entity : entities.keySet()){
if(propertyNames != null && propertyNames.size() > 0){
Method[] methodList = clas.getClass().getMethods();
Method methodName;
for (String propertyName : propertyNames) {
for(Method method : methodList){
if(method.getName().trim().startsWith("set")){
if(propertyName.trim().equalsIgnoreCase(method.getName().substring(3, method.getName().trim().length()))){
methodName = clas.getClass().getMethod(method.getName().trim(),new Class[]{Integer.class});
System.out.println("HERE I GET METHOD NAME ::: " + methodName.getName());
/*
* here one by one i am getting all the Setter methods name from the class .
* but i want a that Setter methods values. Not return type.
*/
}
}
}
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
코드를 게시 할 수 있습니까? 귀하의 질문은 거의 이해가되지 않습니다. –
내 코드를 추가하십시오. –