728x90
반응형
ComParamLogger.Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | package egovframework.com.cmm.util; import java.lang.reflect.Field; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.commons.collections.map.ListOrderedMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import egovframework.rte.psl.dataaccess.util.EgovMap; //import org.apache.log4j.Logger; public class ComParamLogger { // protected static final Log log = LogFactory.getLog(ComParamUtil.class); // private static final Logger logger = LoggerFactory.getLogger(ComParamUtil.class); //logger로 사용할 경우, 하위 logger들과 충돌 때문에 사용안함 // private Logger logger = Logger.getLogger(this.getClass()); //현재 클래스의 depth에서 apache.log4j를 사용할 수 없어서 사용 안함 private static final Logger comParamLogger = LoggerFactory.getLogger(ComParamLogger.class); /** * request의 모든 값을 확인 * * @param reqClassName * @param nowMethod * @param request * @return * @throws Exception */ public static Map<String, Object> requestGetParameterToMap(String reqClassName, String nowMethod, HttpServletRequest request) throws Exception { comParamLogger.debug("# 클래스명:[" + reqClassName + "] " + "메소드명:[" + nowMethod + "] requestGetParameterToMap 시작 #"); Map<String, Object> rtnMap = new HashMap<String, Object>(); Enumeration<?> params = request.getParameterNames(); int cnt = 0; while (params.hasMoreElements()) { String keyName = (String) params.nextElement(); comParamLogger.debug("# Parameter" + cnt + " # " + keyName + " : [" + request.getParameter(keyName) + "]"); rtnMap.put(keyName, request.getParameter(StringUtil.nullString(keyName))); cnt++; } comParamLogger.debug("# 클래스명:[" + reqClassName + "] " + "메소드명:[" + nowMethod + "] requestGetParameterToMap 종료 #"); return rtnMap; } /** * VO의 모든 값을 확인 * * @param reqClassName * @param nowMethod * @param comParamUtilVO * @return * @throws IllegalArgumentException * @throws IllegalAccessException */ public static Object paramToVO(String reqClassName, String nowMethod, Object comParamUtilVO) throws IllegalArgumentException, IllegalAccessException { comParamLogger.debug("# 클래스명:[" + reqClassName + "] " + "메소드명:[" + nowMethod + "] " + "VO명:[" + comParamUtilVO + "] paramToVO 시작 #"); Object obj = comParamUtilVO; int i = 0; for (Field field : obj.getClass().getDeclaredFields()) { field.setAccessible(true); String keyName = field.getName(); Object keyValue = field.get(obj); if (keyValue == null || ("").equals(keyValue.toString())) { keyValue = ""; } comParamLogger.debug("# paramToVO # VO명:[" + comParamUtilVO + "] [" + i + "] keyName:[" + keyName + "] # keyValue:[" + keyValue + "]"); i++; } comParamLogger.debug("# 클래스명:[" + reqClassName + "] " + "메소드명:[" + nowMethod + "] " + "VO명:[" + comParamUtilVO + "] paramToVO 종료 #"); return comParamUtilVO; } public static List listToMap(List requestList) throws Exception { comParamLogger.debug("### ListUtil 시작---------------------------------------------------------------"); List rtnList = new ArrayList(); try { Iterator resultIterator = requestList.iterator(); int i = 0; while (resultIterator.hasNext()) { ListOrderedMap oderKeyMap = (ListOrderedMap) resultIterator.next(); comParamLogger.debug("### ListUtil 1for문 ###" + "Row[" + i + "]의 모든 값 oderKeyMap ==" + oderKeyMap); // String idRd = String.valueOf(oderKeyMap.get("id")); // int id = Integer.parseInt(idRd); // comParamLogger.debug("### ListUtil 1for문 ### id == " + id); EgovMap colMap = new EgovMap(); int j = 0; Set key = oderKeyMap.keySet(); for (Iterator iterator = key.iterator(); iterator.hasNext();) { String keyName = (String) iterator.next(); Object valueName = (Object) oderKeyMap.get(keyName); comParamLogger.debug("### ListUtil 2for문 ###" + "Row[" + i + "]의 colMap[" + j + "] ###" + keyName + " = " + valueName); colMap.put(keyName, valueName); j++; } rtnList.add((EgovMap) colMap); i++; } } catch (Exception e) { comParamLogger.debug("### ListUtil Exception : \n" + e); } comParamLogger.debug("### ListUtil 끝---------------------------------------------------------------"); return rtnList; } } | cs |
String유틸에서 Null처리
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package egovframework.com.cmm.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import com.ibm.icu.text.DecimalFormat; public class StringUtil { public static String nullString(String val) { String res = ""; if (val == null) return ""; if (val == "null") return ""; try { res = val.trim(); } catch (Exception ex) { res = ""; } return res; } } | cs |
호출하고자 하는 매소드에 적어주기
1 2 3 4 5 | /* ######################################################################################################################################## */ String nowMethod = new Object() {}.getClass().getEnclosingMethod().getName(); Map<String, Object> reqGetParameterToMap = ComParamLogger.requestGetParameterToMap(this.getClass().getName().toString(), nowMethod, request); ComParamLogger.paramToVO(OrgController.class.getClass().getName().toString(), nowMethod, orgVO); /* ######################################################################################################################################## */ | cs |
728x90
반응형