|
|
|
@ -1,16 +1,13 @@
|
|
|
|
|
package kr.xit.framework.core.model;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.EqualsAndHashCode;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
import lombok.Setter;
|
|
|
|
|
import lombok.ToString;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
@ -22,514 +19,18 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
* @since 2002. 2. 2.
|
|
|
|
|
* @version 1.0 Copyright(c) XIT All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
@Setter
|
|
|
|
|
@Getter
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@EqualsAndHashCode
|
|
|
|
|
@ToString
|
|
|
|
|
public class BaseVO implements Serializable{
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(BaseVO.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* serialVersionUID
|
|
|
|
|
*/
|
|
|
|
|
private static final long serialVersionUID = 966032273162649197L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int tot_cnt;
|
|
|
|
|
public int getTot_cnt() {
|
|
|
|
|
return tot_cnt;
|
|
|
|
|
}
|
|
|
|
|
public void setTot_cnt(int tot_cnt) {
|
|
|
|
|
this.tot_cnt = tot_cnt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * toString
|
|
|
|
|
// */
|
|
|
|
|
// public String toString() {
|
|
|
|
|
// StringBuffer buffer = new StringBuffer();
|
|
|
|
|
//// buffer.append("\n◁▶FIELD BEGIN◀▷ ◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆");
|
|
|
|
|
// buffer.append("\n◁▶"+this.getClass().getName()+"◀▷ ◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆");
|
|
|
|
|
//
|
|
|
|
|
// Field[] fields = null;
|
|
|
|
|
// Field[] fields1 = this.getClass().getDeclaredFields(); // this 객체의 fields
|
|
|
|
|
// Field[] fields2 = this.getClass().getSuperclass().getDeclaredFields(); // super 객체의 fields
|
|
|
|
|
//
|
|
|
|
|
// // 두 객체의 fields를 합침.
|
|
|
|
|
// fields = new Field[fields1.length + fields2.length];
|
|
|
|
|
// System.arraycopy(fields1, 0, fields, 0, fields1.length);
|
|
|
|
|
// System.arraycopy(fields2, 0, fields, fields1.length, fields2.length);
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// Method _method = null; // getter
|
|
|
|
|
// String _methodName = null; // getter name
|
|
|
|
|
// for (int i = 0; i < fields.length; i++) {
|
|
|
|
|
// // field의 getter name을 작성
|
|
|
|
|
// _methodName = "get" + fields[i].getName().substring(0, 1).toUpperCase() + fields[i].getName().substring(1);
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// // getter를 가져옴
|
|
|
|
|
// _method = this.getClass().getMethod(_methodName, (Class[])null);
|
|
|
|
|
//
|
|
|
|
|
// if (_method != null) {
|
|
|
|
|
// // 출력문자열 작성
|
|
|
|
|
// buffer.append("\n").append(fields[i].getName()).append("=").append(_method.invoke(this, (Object[])null));
|
|
|
|
|
//
|
|
|
|
|
// // 가독성을 위해 컬럼 사이에 ', '를 넣음
|
|
|
|
|
// if (i < fields.length - 1) buffer.append(", ");
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
//// LOGGER.debug(fields[i].getName() + " 속성의 getter method가 존재하지 않거나 접근할 수 없어 출력 문자열에서 누락됩니다.[" + e.getMessage() + "]");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// logger.error(e.getMessage(), e);
|
|
|
|
|
//
|
|
|
|
|
// return super.toString();
|
|
|
|
|
// }
|
|
|
|
|
//// buffer.append("\n◁▶FIELD END◀▷ ◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆");
|
|
|
|
|
// return buffer.toString();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* toString
|
|
|
|
|
*/
|
|
|
|
|
public String toString() {
|
|
|
|
|
return ToStringBuilder.reflectionToString(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: Map을 Object(VO)로 변환하여 반환</pre>
|
|
|
|
|
* @param map
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 4. 24.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
|
public Object convertMapToObject(Map map){
|
|
|
|
|
|
|
|
|
|
Iterator<String> itr = map.keySet().iterator();
|
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
|
String key = (String) itr.next();
|
|
|
|
|
String _methodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
|
|
|
|
|
Method[] _methods1 = this.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
Method[] _methods2 = this.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
|
|
|
|
|
//this와 super의 methods 병합
|
|
|
|
|
Method[] _methods = new Method[_methods1.length+_methods2.length];
|
|
|
|
|
System.arraycopy(_methods1, 0, _methods, 0, _methods1.length);
|
|
|
|
|
System.arraycopy(_methods2, 0, _methods, _methods1.length, _methods2.length);
|
|
|
|
|
|
|
|
|
|
//param set
|
|
|
|
|
try {
|
|
|
|
|
for(Method method : _methods){
|
|
|
|
|
if(_methodName.equals(method.getName())){
|
|
|
|
|
method.invoke(this, map.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: JSONObject을 현재객체(VO)로 변환하여 반환</pre>
|
|
|
|
|
* @param jsonObj JSONObject
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 6. 4.
|
|
|
|
|
*/
|
|
|
|
|
public Object convertJSONObjectToObject(Object jsonObj){
|
|
|
|
|
// if(jsonObj instanceof framework.egov.comext.jfile.org.json.JSONObject) {
|
|
|
|
|
// return this.convertJSONObjectToObject((framework.egov.comext.jfile.org.json.JSONObject)jsonObj);
|
|
|
|
|
// }else if(jsonObj instanceof org.json.simple.JSONObject) {
|
|
|
|
|
// return this.convertJSONObjectToObject((org.json.simple.JSONObject)jsonObj);
|
|
|
|
|
// }else {
|
|
|
|
|
// LOGGER.debug("유효하지 않은 변환 요청");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return this;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jsonObj instanceof org.json.simple.JSONObject) {
|
|
|
|
|
return this.convertJSONObjectToObject((org.json.simple.JSONObject)jsonObj);
|
|
|
|
|
}else {
|
|
|
|
|
logger.debug("유효하지 않은 변환 요청");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private Object convertJSONObjectToObject(org.json.simple.JSONObject jsonObj){
|
|
|
|
|
Iterator<String> itr = jsonObj.keySet().iterator();
|
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
|
String key = (String) itr.next();
|
|
|
|
|
String _methodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
|
|
|
|
|
Method[] _methods1 = this.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
Method[] _methods2 = this.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
|
|
|
|
|
//this와 super의 methods 병합
|
|
|
|
|
Method[] _methods = new Method[_methods1.length+_methods2.length];
|
|
|
|
|
System.arraycopy(_methods1, 0, _methods, 0, _methods1.length);
|
|
|
|
|
System.arraycopy(_methods2, 0, _methods, _methods1.length, _methods2.length);
|
|
|
|
|
|
|
|
|
|
//param set
|
|
|
|
|
try {
|
|
|
|
|
for(Method method : _methods){
|
|
|
|
|
if(_methodName.equals(method.getName())){
|
|
|
|
|
method.invoke(this, jsonObj.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
// private Object convertJSONObjectToObject(framework.egov.comext.jfile.org.json.JSONObject jsonObj){
|
|
|
|
|
// Iterator<String> itr = jsonObj.keys();
|
|
|
|
|
// while (itr.hasNext()) {
|
|
|
|
|
// String key = (String) itr.next();
|
|
|
|
|
// String _methodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
//
|
|
|
|
|
// Method[] _methods1 = this.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
// Method[] _methods2 = this.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
//
|
|
|
|
|
// //this와 super의 methods 병합
|
|
|
|
|
// Method[] _methods = new Method[_methods1.length+_methods2.length];
|
|
|
|
|
// System.arraycopy(_methods1, 0, _methods, 0, _methods1.length);
|
|
|
|
|
// System.arraycopy(_methods2, 0, _methods, _methods1.length, _methods2.length);
|
|
|
|
|
//
|
|
|
|
|
// //param set
|
|
|
|
|
// try {
|
|
|
|
|
// for(Method method : _methods){
|
|
|
|
|
// if(_methodName.equals(method.getName())){
|
|
|
|
|
// method.invoke(this, jsonObj.get(key));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } catch (IllegalAccessException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// } catch (IllegalArgumentException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// } catch (InvocationTargetException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// } catch (JSONException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return this;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: Object(VO)간 동일 필드 매핑 후 반환</pre>
|
|
|
|
|
* @param fromClass
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 6. 4.
|
|
|
|
|
*/
|
|
|
|
|
public Object convertObjectToObject(Object fromClass) {
|
|
|
|
|
|
|
|
|
|
//this객체 Field 설정
|
|
|
|
|
Field[] fields = null;
|
|
|
|
|
Field[] fields1 = this.getClass().getDeclaredFields(); // this 객체의 fields
|
|
|
|
|
Field[] fields2 = this.getClass().getSuperclass().getDeclaredFields(); // super 객체의 fields
|
|
|
|
|
fields = new Field[fields1.length + fields2.length];
|
|
|
|
|
System.arraycopy(fields1, 0, fields, 0, fields1.length);
|
|
|
|
|
System.arraycopy(fields2, 0, fields, fields1.length, fields2.length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Field field : fields) {
|
|
|
|
|
String key = field.getName();
|
|
|
|
|
String _getterMethodName = "get" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
String _setterMethodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//fromClass의 메소드 취합
|
|
|
|
|
Method[] _methods1 = fromClass.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
Method[] _methods2 = fromClass.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
Map<String, String> _mMethods = new HashMap<>();
|
|
|
|
|
for(Method method : _methods1)
|
|
|
|
|
_mMethods.put(method.getName(), method.getName());
|
|
|
|
|
for(Method method : _methods2)
|
|
|
|
|
_mMethods.put(method.getName(), method.getName());
|
|
|
|
|
|
|
|
|
|
//param set
|
|
|
|
|
if(_mMethods.get(_getterMethodName)!=null) {
|
|
|
|
|
try {
|
|
|
|
|
Field fromField = fromClass.getClass().getDeclaredField(key);
|
|
|
|
|
Object value = null;
|
|
|
|
|
fromField.setAccessible(true);
|
|
|
|
|
value = fromField.get(fromClass);
|
|
|
|
|
fromField.setAccessible(false);
|
|
|
|
|
|
|
|
|
|
Method method = this.getClass().getMethod(_setterMethodName, String.class);
|
|
|
|
|
method.invoke(this, value);
|
|
|
|
|
|
|
|
|
|
}catch (SecurityException | NoSuchMethodException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: 부모객체를 자식객체로 캐스팅 후 반환한다.</pre>
|
|
|
|
|
* @param toClass
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 8. 9.
|
|
|
|
|
*/
|
|
|
|
|
public Object downCast(Object toClass) {
|
|
|
|
|
return this.convertToObject(toClass);
|
|
|
|
|
}
|
|
|
|
|
// /**
|
|
|
|
|
// * <pre>메소드 설명: 현재 객체를 대상객체(toClass)로 필드매핑하여 반환</pre>
|
|
|
|
|
// * @param toClass
|
|
|
|
|
// * @return Object 요청처리 후 응답객체
|
|
|
|
|
// * @author: 박민규
|
|
|
|
|
// * @date: 2019. 8. 9.
|
|
|
|
|
// */
|
|
|
|
|
// public Object convertToObject(Object toClass) {
|
|
|
|
|
//
|
|
|
|
|
// //this객체 Field 설정
|
|
|
|
|
// Field[] fields = null;
|
|
|
|
|
// Field[] fields1 = toClass.getClass().getDeclaredFields(); // this 객체의 fields
|
|
|
|
|
// Field[] fields2 = toClass.getClass().getSuperclass().getDeclaredFields(); // super 객체의 fields
|
|
|
|
|
// fields = new Field[fields1.length + fields2.length];
|
|
|
|
|
// System.arraycopy(fields1, 0, fields, 0, fields1.length);
|
|
|
|
|
// System.arraycopy(fields2, 0, fields, fields1.length, fields2.length);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// for(Field field : fields) {
|
|
|
|
|
// String key = field.getName();
|
|
|
|
|
// String _getterMethodName = "get" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
// String _setterMethodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// //fromClass의 메소드 취합
|
|
|
|
|
// Method[] _methods1 = this.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
// Method[] _methods2 = this.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
// Map<String, String> _mMethods = new HashMap<>();
|
|
|
|
|
// for(Method method : _methods1)
|
|
|
|
|
// _mMethods.put(method.getName(), method.getName());
|
|
|
|
|
// for(Method method : _methods2)
|
|
|
|
|
// _mMethods.put(method.getName(), method.getName());
|
|
|
|
|
//
|
|
|
|
|
// //param set
|
|
|
|
|
// if(_mMethods.get(_getterMethodName)!=null) {
|
|
|
|
|
// try {
|
|
|
|
|
// Field fromField = this.getClass().getDeclaredField(key);
|
|
|
|
|
// Object value = null;
|
|
|
|
|
// fromField.setAccessible(true);
|
|
|
|
|
// value = fromField.get(this);
|
|
|
|
|
// fromField.setAccessible(false);
|
|
|
|
|
//
|
|
|
|
|
//// Method method = toClass.getClass().getMethod(_setterMethodName, String.class);
|
|
|
|
|
// Method method = toClass.getClass().getMethod(_setterMethodName, this.getClass().getDeclaredField(key).getType());
|
|
|
|
|
// method.invoke(toClass, value);
|
|
|
|
|
//
|
|
|
|
|
// }catch (SecurityException | NoSuchMethodException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// } catch (NoSuchFieldException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return toClass;
|
|
|
|
|
// }
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: 현재 객체를 대상객체(toClass)로 필드매핑하여 반환</pre>
|
|
|
|
|
* @param toClass
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 8. 9.
|
|
|
|
|
*/
|
|
|
|
|
public Object convertToObject(Object toClass) {
|
|
|
|
|
|
|
|
|
|
//toClass 전체 필드 get
|
|
|
|
|
int _cntToFields = 0;
|
|
|
|
|
Class _tmpToClass = toClass.getClass();
|
|
|
|
|
while(true) {
|
|
|
|
|
Field[] fields = _tmpToClass.getDeclaredFields();
|
|
|
|
|
_cntToFields += fields.length;
|
|
|
|
|
|
|
|
|
|
_tmpToClass = _tmpToClass.getSuperclass();
|
|
|
|
|
if(_tmpToClass==null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//toClass 전체 필드 set
|
|
|
|
|
Field[] toFields = new Field[_cntToFields];
|
|
|
|
|
_tmpToClass = toClass.getClass();
|
|
|
|
|
int idx = 0;
|
|
|
|
|
while(true) {
|
|
|
|
|
Field[] flds = _tmpToClass.getDeclaredFields();
|
|
|
|
|
|
|
|
|
|
System.arraycopy(flds, 0, toFields, idx, flds.length);
|
|
|
|
|
idx += flds.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_tmpToClass = _tmpToClass.getSuperclass();
|
|
|
|
|
if(_tmpToClass==null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//fromClass 전체 메소드 set
|
|
|
|
|
Class _tmpFromClass = this.getClass();
|
|
|
|
|
Map<String, String> _mMethods = new HashMap<>();
|
|
|
|
|
while(true) {
|
|
|
|
|
Method[] _methods = _tmpFromClass.getDeclaredMethods();
|
|
|
|
|
for(Method method : _methods)
|
|
|
|
|
_mMethods.put(method.getName(), method.getName());
|
|
|
|
|
|
|
|
|
|
_tmpFromClass = _tmpFromClass.getSuperclass();
|
|
|
|
|
if(_tmpFromClass==null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Field field : toFields) {
|
|
|
|
|
String key = field.getName();
|
|
|
|
|
String _getterMethodName = "get" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
// String _setterMethodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//param set
|
|
|
|
|
if(_mMethods.get(_getterMethodName)!=null) {
|
|
|
|
|
try {
|
|
|
|
|
//value get
|
|
|
|
|
Field _fromField = null;
|
|
|
|
|
_tmpFromClass = this.getClass();
|
|
|
|
|
while(true) {
|
|
|
|
|
try {
|
|
|
|
|
_fromField = _tmpFromClass.getDeclaredField(key);
|
|
|
|
|
break;
|
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_tmpFromClass = _tmpFromClass.getSuperclass();
|
|
|
|
|
if(_tmpFromClass==null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_fromField.setAccessible(true);
|
|
|
|
|
Object value = _fromField.get(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//value set
|
|
|
|
|
_tmpToClass = toClass.getClass();
|
|
|
|
|
Field toField = null;
|
|
|
|
|
while(true) {
|
|
|
|
|
try {
|
|
|
|
|
toField = _tmpToClass.getDeclaredField(key);
|
|
|
|
|
toField.setAccessible(true);
|
|
|
|
|
toField.set(toClass, value);
|
|
|
|
|
break;
|
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_tmpToClass = _tmpToClass.getSuperclass();
|
|
|
|
|
if(_tmpToClass==null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (SecurityException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IllegalAccessException | IllegalArgumentException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return toClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: Map을 Object(VO)로 변환하여 반환</pre>
|
|
|
|
|
* @param map
|
|
|
|
|
* @param objClass
|
|
|
|
|
* @return Object 요청처리 후 응답객체
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2019. 4. 24.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
|
public Object convertMapToObject(Map map, Object objClass){
|
|
|
|
|
|
|
|
|
|
Iterator<String> itr = map.keySet().iterator();
|
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
|
String key = (String) itr.next();
|
|
|
|
|
String _methodName = "set" + key.substring(0,1).toUpperCase() + key.substring(1);
|
|
|
|
|
|
|
|
|
|
Method[] _methods1 = objClass.getClass().getDeclaredMethods(); //this 객체의 methods
|
|
|
|
|
Method[] _methods2 = objClass.getClass().getSuperclass().getDeclaredMethods(); //super 객체의 methods
|
|
|
|
|
|
|
|
|
|
//this와 super의 methods 병합
|
|
|
|
|
Method[] _methods = new Method[_methods1.length+_methods2.length];
|
|
|
|
|
System.arraycopy(_methods1, 0, _methods, 0, _methods1.length);
|
|
|
|
|
System.arraycopy(_methods2, 0, _methods, _methods1.length, _methods2.length);
|
|
|
|
|
|
|
|
|
|
//param set
|
|
|
|
|
try {
|
|
|
|
|
for(Method method : _methods){
|
|
|
|
|
if(_methodName.equals(method.getName())){
|
|
|
|
|
method.invoke(objClass, map.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return objClass;
|
|
|
|
|
}
|
|
|
|
|
private int totCnt;
|
|
|
|
|
}
|
|
|
|
|