2009년 04월 14일
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용식
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)








☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]