日期:2014-05-20  浏览次数:20782 次

请教使用mybatis用到的注解方式转换为xml配置方式
使用mybatis拦截分页时用的一个拦截器
这是xml文件中配置的
Java code

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />    
        <property name="plugins" ref="paginationInterceptor"/>
    </bean>
    <bean id="paginationInterceptor" class="**.PaginationInterceptor" />    


以下是PaginationInterceptor类
Java code

//只拦截select部分
@Intercepts( {@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class,
        RowBounds.class, ResultHandler.class})})
public class PaginationInterceptor implements Interceptor {

    public Object intercept(Invocation invocation) throws Throwable {
    ……
    ……
    }
}



注解部分
@Intercepts( {@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class,
  RowBounds.class, ResultHandler.class})})
如果不用注解方式,直接在xml里配置,该怎么写呢?

------解决方案--------------------
你这个和MyBatis就没多大关系...这不是Spring的拦截器吗...
------解决方案--------------------

<bean id="ServiceAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="proxyTargetClass" value="true"></property>
<property name="beanNames">
<list>
<value>*Service</value> ..
</list>
</property>
</bean>
------解决方案--------------------
这个拦截器操作的是plugin
这本身就是MyBatis的底层实现,这部分没有xml
重写了plugin就意味着,你改变了MyBatis本身的执行逻辑