JAVA动态调用当前对象里面的方法

	@RequestMapping("/test")
	@ResponseBody
	public String test(HttpServletRequest request,HttpServletResponse response) throws Exception{
		String m=request.getParameter("m");
		
		this.getClass().getMethod("test1", new Class[]{}).invoke(this, new Object[]{}); 
		this.getClass().getMethod("test2", new Class[]{}).invoke(this, new Object[]{});
		
		return "hello!";
	}
	

	public void test1(){
		
		Orderinfo orderinfo = orderinfoService.findOrderinfoByOrderid("1473751650136");
		System.out.println(orderinfo.getTotalmoney());
		
	}
	public void test2(){
		
		Orderinfo orderinfo = orderinfoService.findOrderinfoByOrderid("1473814346230");
		
		System.out.println(orderinfo.getTotalmoney());
		
	}

你可能感兴趣的:(JAVA动态调用当前对象里面的方法)