反射处理

String transCode = transactionBM.getTranCode();
String methodName = transCodeMethodMap.get(transCode);
IValidate validate = bankCodeHandleMap.get(transactionBM.getBankCode());
//定义参数类型
@SuppressWarnings("rawtypes")
Class[] parameterTypes  = new Class[1];
parameterTypes [0] = TransactionBM.class;
//设置参数
Object[] argObjs = new Object[1];
argObjs[0] = transactionBM;
//数据校验
Method dataMethod = validate.getClass().getMethod(methodName, parameterTypes);
dataMethod.setAccessible(true);
String msg = (String)dataMethod.invoke(validate, argObjs);


<bean id="validateFactory" class="com.tianan.bis.validate.ValidateFactory">
  	<property name="transCodeMethodMap">   
      <map>   
        <entry key="170100" value="rePrintNote"/>
        <entry key="170200" value="init"/>   
        <entry key="170300" value="submit"/>   
      </map>   
    </property> 
    <property name="bankCodeHandleMap">   
      <map>   
      	<entry key="5" value-ref="new_ABC_Validation"/>
        <entry key="6" value-ref="psbc_cs_validation"/>
        <entry key="7" value-ref="newccb_cs_validation"/>
      </map>   
    </property> 
  </bean>

猜你喜欢

转载自lysunki.iteye.com/blog/2203200