package com.ba.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 思路分析:
* 1、创建一个shoutObject方法返回值为Object接收参数有:request、response、type、t
* 2、获取T该类公共成员的 Class 对象的数组
* 3、获取该类与指定名和参数相匹配的方法的 Method 对象数组,然后进行遍历,用getName()方法得到我们的 T 的所有方法
* 4、对jsp传过来的type与T的方法进行比较,如果相等,那么就拼接方法和参数,然后执行将结果返回即可
* @author Administrator
*
*/
//实现代码
public class UserServletReflect {
public <T> Object shoutObject(HttpServletRequest request,HttpServletResponse response,String type,T t){
try {
Class
Java利用反射调用方法
最新推荐文章于 2024-05-27 20:55:58 发布