package com.interceptor; import java.lang.reflect.Proxy; import com.yihaomen.mybatis.model.Model; import com.yihaomen.mybatis.model.ModelImpl; import com.yihaomen.mybatis.model.User; public class GetProxy { /** * 得到代理对象 * @param obj //对象操作实例 * @return */ public Object getProxy(Object obj) { // 业务代理类 SessionTrascationInvocationHandler st = new SessionTrascationInvocationHandler(obj); // 获得代理类($Proxy0 extends Proxy implements Manager)的实例. Object proxy = Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(),st); return proxy; } public static void main(String[] args) { Dao daoImpl = new DaoImpl(); Dao dao = (Dao)new GetProxy().getProxy(daoImpl); /** * 添加User */ User adduser = new User(); adduser.setId(4); adduser.setUserName("生命之重"); adduser.setUserAge("20"); adduser.setUserAddress("sichuang,chengdu"); dao.add(adduser); } }


可乐要加冰1 LV8
2024年4月1日
微信网友_6815604991741952 LV1
2024年1月10日
Kaiaahh LV2
2024年1月4日
zuishuaidebaba LV2
2023年6月19日
李亮 LV19
2023年3月6日
bibibibi
2022年11月1日
暂无贡献等级
我睡觉时不困 LV7
2022年10月30日
shufsjnjksf LV1
2022年10月18日
dicaprio LV1
2022年10月2日
sweetbox LV10
2022年9月6日