public int checkMethodGetdata(RuleRecord ruleRecord,String methodName, JSONObject paramsJson,ProductBean productbean) throws IllegalAccessException, InstantiationException, BusinessException { Class<?> c = iInnerRuleGetDataService.getClass(); Object obj = c.newInstance(); try { Method method = c.getMethod(methodName,RuleRecord.class, JSONObject.class,ProductBean.class); int result = Integer.parseInt(String.valueOf(method.invoke(obj, new Object[]{ruleRecord,paramsJson,productbean}))); return result; }catch (NoSuchMethodException e){ LOG.error("找不到执行方法:[{}]", methodName); throw new BusinessException(ResponseCode.REQUEST_ERROR_PROGRAM_EXCEPTION, "找不到执行方法", true); }catch (Exception e){ LOG.error("程序异常:[{}]", e.getMessage()); throw new BusinessException(ResponseCode.REQUEST_ERROR_PROGRAM_EXCEPTION, "程序异常", true); }}
其中:
methodName 为方法名 其余为参数 参数用object[] 数组隔开
springMVC 通过反射调用类方法
最新推荐文章于 2024-05-14 19:38:58 发布