mybatis插件

`@Intercepts({ @Signature(type = StatementHandler.class,
method = "prepare",
args = {Connection.class})}) public class MyBatisInterceptor implements Interceptor {sql

[@Override](https://my.oschina.net/u/1162528)
public Object intercept(Invocation invocation) throws Throwable {
	StatementHandler statementHandler = (StatementHandler) invocation.getTarget();  
	MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
	
	String sql = (String)metaStatementHandler.getValue("delegate.boundSql.sql");  
	System.out.println("sql : "+sql);
	metaStatementHandler.setValue("delegate.boundSql.sql", sql +"  limit " + 1);
	return invocation.proceed();
}

[@Override](https://my.oschina.net/u/1162528)
public Object plugin(Object target) {
	return Plugin.wrap(target, this);
}

[@Override](https://my.oschina.net/u/1162528)
public void setProperties(Properties properties) {
	
}

}`ide

自制插件類需實現Interceptor接口,且註解必須指明對哪一個方法進行攔截,並將此類配置在sqlconfig裏this

相關文章
相關標籤/搜索