/** * @author tandg * */ @Controller public class MainController extends BaseController { Logger log = Logger.getLogger(MainController.class); @Autowired private UserService userService; @RequestMapping(value="/login.do") public String Login(@RequestParam("v") String version) { Method m = null; try { String currMethodName = Thread.currentThread().getStackTrace()[1].getMethodName();//获取当前请求的方法名 m = getVersionMethod(currMethodName, version); return (String) m.invoke(this); } catch (Exception ex) { log.error("Abnormal request interface :"+ex.getMessage(), ex); JSONObject result = new JSONObject(); result.put("Fail", "Abnormal request interface :"+ex.getMessage()); return result.toString(); } } /** * 最新版本登录方法 */ public String Login() { /** * 处理登录业务逻辑代码... */ return null; } /** * 旧版本登录方法 */ public String Login1_0() { /** * 处理登录业务逻辑代码... */ return null; } /** * 处理请求参数 */ public Map<String, Object> getParamMap(HttpServletRequest req) { Map paramMap = new HashMap(); paramMap.putAll(req.getParameterMap()); return paramMap; } /** * controller 版本选择 * * @param currMethodName * @param version * @return * @throws SecurityException * @throws NoSuchMethodException */ public Method getVersionMethod(String currMethodName, String version) throws SecurityException, NoSuchMethodException { Class c = this.getClass(); Method m = null; //比对版本,如v=1.0 if (version.equalsIgnoreCase(ServerConfig.VERSION)) { m = c.getMethod(currMethodName); } else { m = c.getMethod(currMethodName + version); } return m; } }
时间: 2024-10-09 04:03:26