java 根据类名及方法名获取结果值
@Slf4j
@Component
public class GetMsgAssembly {
@Resource
private ApplicationContext applicationContext;
public String getMsg(String className, String methodName, Users users) {
TestService testService = (TestService) applicationContext.getBean(className);
try {
Method declaredMethod = testService.getClass().getDeclaredMethod(methodName, Users.class);
Object resultValue = declaredMethod.invoke(testService, users);
log.info("返回值信息:{}", JsonUtils.toJson(resultValue));
return String.valueOf(resultValue);
} catch (Exception e) {
e.printStackTrace();
log.error("查看判定值异常:{}", e.getMessage(), e);
}
return "";
}
}