Class<?> cls = Class.forName("패키지명" + "class 이름");//클래스의 메타정보 불러오기
Object obj = cls.newInstance();//메타정보로 인스턴스 생성해서 메모리에 올리기
//여기까지는 new class
Class<?> dtoCls = obj.getClass();//생성한 인스턴스로 클래스 형태로 불러오기
//Field 가져오기
Field field[]= dtoCls.getDeclaredFields(); //public으로 지정한 field명 가져오기
//Method 사용법
//생성자 있는 경우
Method setMethod = dtoCls.getMethod("set" + column, String.class); //method 불러오기
setMethod.invoke(obj, data); // method 실행
//return 있는 경우
Method getMethod = dtoCls.getMethod("get" + column); //method 불러오기
String result=getMethod.invoke(obj); // method 실행
https://javacan.tistory.com/tag/Method.invoke%28%29
https://pupustory.tistory.com/192
https://futurists.tistory.com/43
'Java' 카테고리의 다른 글
jaxb 관련 자료 모음 (0) | 2020.01.21 |
---|---|
java list java.lang.indexoutofboundsexception: index: 1, size: 0 오류 해결 (0) | 2019.10.21 |