import java.lang.reflect.Field;
import org.apache.commons.beanutils.BeanUtils;
..
..
public String intercept(ActionInvocation invocation) throws Exception {
log.info("---------- 파라미터 Bean에 셋팅 ----------");
Object action = invocation.getAction();
Field fs [] = action.getClass().getDeclaredFields();
for( Field f : fs ){
if( f.getName().indexOf("Bean") > 0 ){
String s [] = StringUtils.split(f.toString(), " ");
if( s.length == 3 ){
Class cls = Class.forName(s[1]);
Object obj = cls.newInstance();
BeanUtils.copyProperties(obj, ServletActionContext.getRequest().getParameterMap());
f.setAccessible(true);
f.set(action, obj);
}
}
}
return invocation.invoke();
}
Reflection 예제(Parameter 멤버변수에 자동 담기)
2013. 6. 4. 10:39