By way of reflecting arbitrary assignment method in class Class

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;


@Component
public class SetPlatformUtils {
private static final CoreServiceType c = CoreServiceType.getInstance();

void setval public (Object obj, String methodName, String Platform) {
// get the representative obj entity class object class
Class obj.getClass clazz = ();
Method, Method = null;
the try {
methods specified object class // Get
= clazz.getMethod method (methodName, String.class);
// method to assign
IF (StringUtils.isBlank (Platform)) {
Method.invoke (obj, c.CODE.get ( ". 1"));
} {the else
method .invoke (obj, c.CODE.get (Platform));
}
}
the catch (Exception E) {
logger.error ( "secondary classification stored error reflecting tools, obj: {}, methodName: {}, platform: } {, ", obj, methodName, Platform);
}
}
}

Guess you like

Origin www.cnblogs.com/bin-zhao/p/11609374.html