This instance is an impersonation security check
The proxy object interface defines Java code public interface Usermanager {public void Aaduser (user user); public void Deletebyid (int id); public void UpdateUser (user user); Public User FindByID (int id); }
Implement Java code public class usermanagerimp implements usermanager { by proxy object interface @Override public void aaduser (User user) { system.out.println ("---------- AddUser------------"); } @Override public void deletebyid (int id) { system.out.println ("----------Deletebyid------------"); } @Override public user findbyid (int id) { System.out.println ("----------FindByID------------"); return null; } @Override public void updateuser (user user) { system.out.println ("----------updateuser------------"); } }
Define a User object Java code public class user { private int id; private String name; private int age; public String GetName () { return name; } public void setname (String name) { this.name = name; } public int getage () { return age; } public void setage (int age) { this.age = age; } Public int getid () { return id; } public void setid (int ID) { this.id = id; } }
Inherit Invocationhandler interface Java code package hb.proxy; import java.lang.reflect.invocationhandler; import java.lang.reflect.method; import java.lang.reflect.proxy; /* * 1, dynamic proxy class must implement Invocationhandler interface, To implement the Invoke () method */ public class securityhandler implements invocationhandler { private Object targetObject; /* * The following method is to get the proxy object, if not the proxy object, this effect is not useful * the last parameter is the Invocationhandler interface, which is why the dynamic proxy object must implement this interface * The resulting proxy object executes the Invoke () method */ public object newproxy (object targetobject) { this.targetobject = targetobject;