코드 사본은 다음과 같습니다.
패키지 com.java.db;
java.lang.reflect.constructor import;
import java.lang.reflect.field;
import java.lang.reflect.invocationTargetexception;
import java.lang.reflect.method;
java.util.arraylist 가져 오기;
import java.util.arrays;
import java.util.iterator;
Java.util.list 가져 오기;
java.util.map import;
com.java.entity.bookshelf import;
import com.java.util.getmetadatacloumname;
공개 클래스 getNewinstances <t> {
클래스 [] cl = {};
개체 [] ob = {};
/**
* 각 사용 후 비워 지도록 설정하면 누적됩니다.
*/
public void setNullToArrays () {
this.cl = new Class [] {};
this.ob = new Object [] {};
}
/**
* 객체 배열을 복사하십시오
*
* @param obj
* 시공 방법에 필요한 실제 값
* @반품
*/
public object [] getObjectArrays (Object obj) {
ob = arrays.copyof (ob, ob.length + 1);
ob [ob.length -1] = obj;
반환 OB;
}
/**
* 클래스 배열을 복사하십시오
*
* @Param Cla
* 추가 할 클래스
*
* @반품
*/
@suppresswarnings ( "확인되지 않은")
public class [] getClassArrays (class <?> cla) {
if (cla! = null) {
cl = arrays.copyof (cl, cl.length + 1);
cl [cl.length -1] = CLA;
CL;
}또 다른{
CL;
}
}
/**
* 수업 인스턴스를 얻으십시오
*
* @Param Clazz
* 수업은 인스턴스화됩니다
* 인스턴스화 후 @return 클래스
* @throws InstantiationException
* @Throws 불법 행위 예고
* @Throws 불법 행정 exception
* @Throws SecurityException
* @throws invociationTargetexception
* @throws nosuchmethodexception
*/
@suppresswarnings ( "확인되지 않은")
공개 대상 getClassNewinstance (클래스 <?> Clazz)
InstantiationException, 불법 행위 예고,
불법적 인 exception, SecurityException,
invocationTargetexception, nosuchmethodexception {
Object oj = null;
cons = clazz.getDeclaredConstructors (); // 생성자를 얻습니다
클래스 [] cla = cons [1] .getParameterTypes ();
System.out.println ( "필드 생성자 매개 변수의 크기를 추가할지 여부를 사용자에게 팁 :"+cla.length);
for (int i = 0; i <cla.length; i ++) {
문자열 classstr = cla [i] .toString ();
// system.out.println ( "인수 유형 :"+classstr);
if (classstr.equals ( "class java.lang.string") {
getClassArrays (String.class);
} else if (classstr.equals ( "int")) {
getClassArrays (int.class);
} else if (classstr.equals ( "double")) {
getClassArrays (double.class);
} else if (classstr.equals ( "boolean")) {
getClassArrays (boolean.class);
} else if (classstr.equals ( "float")) {
getClassArrays (float.class);
} else if (classstr.equals ( "class java.lang.integer") {
getClassArrays (integer.class);
} else if (classstr.equals ( "class java.lang.float")) {
getClassArrays (float.class);
}
}
oj = clazz.newinstance (); // Bdoperater에서 현재 객체의 특정 인스턴스화 구조를 반환합니다.
귀환 OJ;
}
/**
* 생성자를 통해 특정 인스턴스 클래스를 얻습니다
* @Param Clazz
* @반품
* @Throws 불법 행정 exception
* @Throws SecurityException
* @throws InstantiationException
* @Throws 불법 행위 예고
* @throws invociationTargetexception
* @throws nosuchmethodexception
*/
공개 대상 getObjcon (class <?> clazz)은 불법 행위 exception, 보안 exception, InstantiationException, 불법 행사 지출, invocationTargetexception, nosuchmethodexception {를 던집니다.
Object obj = null;
obj = this.getClassNewinstance (Clazz);
반환 obj;
}
/**
* 객체의 인스턴스를 얻으십시오
* @Param Clazz
* @반품
* @throws InstantiationException
* @Throws 불법 행위 예고
*/
공개 대상 getNewinstance (클래스 클레이즈)는 인스턴티션 exception, 불법 행위 지출 {{
Object obj = null;
obj = clazz.newinstance ();
반환 obj;
}
/**
* 반사를 기반으로 클래스의 모든 속성을 얻으십시오.
* 검색 해야하는 @Param Clazz 클래스
* @return Attribute Collection
* @Throws SecurityException
* @Throws 불법 행정 exception
* @throws InstantiationException
* @Throws 불법 행위 예고
* @throws invociationTargetexception
* @throws nosuchmethodexception
*/
공개 필드 [] getFielsDarray (클래스 <botort> Clazz)는 SecurityException, INSTANTIATIONEXCEPTION, InstantiationException, INEGALACCESSException, invocationTargeteXception, NosuchMethodexception {
필드 [] fields = null;
fields = clazz.getDeclaredFields ();
리턴 필드;
}
/**
* 문자열에 따라 세터 형식 속성을 가져옵니다
* @param str 속성 포맷 해야하는 속성
* @반품
*/
공개 문자열 getSetterstr (String str) {
문자열 정보 = null;
문자열 strvalue = str.substring (0,1) .toupperCase ();
info = "set"+strvalue+str.substring (1, str.length ());
반품 정보;
}
/**
* setxx를 xx로 복원하십시오
* @param str
* @반품
*/
공개 문자열 setsetstr (String str) {
문자열 정보 = null;
문자열 strvalue = str.substring (3, str.length ());
문자열 아래 = strvalue.substring (0) .tolowercase (). 서브 스트링 (0,1);
info = lower+str.substring (4, str.length ());
반품 정보;
}
/**
* 수업에서 메소드를 얻으십시오
* @Param Clazz 방법을 얻기 위해 클래스가 필요했습니다
* @반품
*/
공개 방법 [] getMethodSarray (클래스 Clazz) {
메소드 [] 메소드 = clazz.getMethods ();
반환 방법;
}
/**
* List <map>에 따라 생성자를 인스턴스화하십시오
* @param listmap
* @Param Clazz
* @param tablename 데이터베이스 이름
* @반품
* @throws nosuchmethodexception
* @throws invociationTargetexception
* @Throws SecurityException
* @Throws 불법 행정 exception
* @Throws 불법 행위 예고
* @throws InstantiationException
*/
@suppresswarnings ({ "선택되지 않은"})
public list <bood> getListBymap (list <map <string, object >> listMap, 클래스 클라지, 문자열 태블 이름)은 인스턴티션 exception, 불법 행위 exception, 불법 행위, SecurityException, invocationTargetexception, nosuchmethodexception {
list <boodge> listlast = new ArrayList <Object> ();
List <string> metalist = getmetadatacloumname.getCloumnamelist (TableName);
iterator <map <string, object >> it = listmap.iterator ();
while (it.hasnext ()) {
map <string, object> map = it.next ();
iterator <string> iitt = metalist.iterator ();
while (iitt.hasnext ()) {
문자열 정보 = iitt.next ();
this.getObjectArrays (map.get (info));
}
System.out.println ( "Call Reflection :"+this.cl.length+""+this.ob.length);
Object TOBJ = this.GetClassNewInstance (Clazz) .getClass (). getConstructor (this.cl) .newinstance (this.ob);
listlast.add (tobj);
this.setNullToArrays ();
}
리턴리스트 라스트;
}
public static void main (String [] args) {
getNewInstances ge = new getNewInstances ();
System.out.println (ge.getSetterstr ( "네임 스페이스") == "setNamespace");
System.out.println ( "1a"== "1a");
system.out.println (ge.setsetstr ( "setnamespace"));
}
}