📄 daomethodinterceptor.java
字号:
package cn.cja.dao;
import java.lang.reflect.Method;
import java.sql.Connection;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import cn.cja.sql.Query;
import cn.cja.sql.Update;
public class DAOMethodInterceptor implements MethodInterceptor{
private IConnectionProvider connectionManager;
public DAOMethodInterceptor(IConnectionProvider connectionManager) {
this.connectionManager=connectionManager;
}
public Object intercept(Object object, Method method, Object[] params,
MethodProxy proxy) throws Throwable {
Query query=method.getAnnotation(Query.class);
if(query!=null)
{
QueryController selectController=new QueryController();
Class type=method.getReturnType();
return selectController.query(query,connectionManager.get(),params,type,object);
}
Update update=method.getAnnotation(Update.class);
if(update!=null)
{
UpdateController updateController=new UpdateController();
Class type=method.getReturnType();
if(type.equals(Integer.class)||type.equals(int.class))
{
return updateController.update(update,connectionManager.get(),params);
}
else
{
updateController.update(update,connectionManager.get(),params);
return null;
}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -