Egloos | Log-in


Domain Class toString 메서드 <펌>

@Override
public String toString() {
      BeanWrapper domain = PropertyAccessorFactory.forBeanPropertyAccess(this); //spring
     Class<클래스명> clazz = 클래스명.class;
     List<Field> fields = new ArrayList<Field>();
        while (clazz != null) {
            CollectionUtils.addAll(fields, clazz.getDeclaredFields()); //apache-commons-util
            clazz = (Class<클래스명>) clazz.getSuperclass();
        }
       
        StringBuffer sb = new StringBuffer();
       
        for (Field field : fields) {
         Object sourceValue = domain.getPropertyValue(field.getName());
         
         sb.append("["+field.getName()+"]=["+sourceValue+"] \n");
        }
       
        return sb.toString();
}

출처 - http://devyongsik.tistory.com/?page=6 DEV용식

by 행복하자 | 2009/04/14 13:44 | JAVA 향기 | 트랙백 | 덧글(0)

트랙백 주소 : http://hongsgo.egloos.com/tb/2172052
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶