使用反射优化大量if-else代码 一

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
{ 
   String action = req.getParameter("action"); 
   try 
   {
       Method method = this.getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class); 
       method.invoke(this, req, resp); 
   } catch (Exception e) 
   { 
       e.printStackTrace(); 
   } 
}

 

posted on 2022-03-05 14:43  金满仓  阅读(73)  评论(0)    收藏  举报

导航