首页>代码>mybatis增删改查,关联查询,带数据库的demo>/mybatisdemo/src/com/interceptor/GetProxy.java
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日
李亮  LV19 2023年3月6日
我睡觉时不困  LV7 2022年10月30日
dicaprio  LV1 2022年10月2日
cddhhh  LV1 2022年7月3日
靛紫1234  LV4 2022年4月28日
wittylin  LV1 2022年4月28日
Altria  LV5 2021年8月18日
ommmly  LV5 2021年6月9日
hjd3983  LV10 2020年12月1日
最近浏览更多
可乐要加冰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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友