Coder Social home page Coder Social logo

Comments (4)

White-Duke avatar White-Duke commented on June 24, 2024

我现在自己实现了配置方法,没有使用starter了,还有一种方式是,直接定义一个PageInterceptor Bean就可以了。

@configuration
@order(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(PageHelperProperties.class)
public class PageHelperConfig {

@Autowired
private PageHelperProperties pageHelperProperties;

@Bean
public BeanPostProcessor pageHelperBeanPostProcessor() {
    PageInterceptor interceptor = new PageInterceptor();
    interceptor.setProperties(pageHelperProperties.getProperties());

    return new BeanPostProcessor() {
        @Override
        public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            return bean;
        }

        @Override
        public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
            if (bean instanceof SqlSessionFactory) {
                SqlSessionFactory sqlSessionFactory = (SqlSessionFactory) bean;
                if (!sqlSessionFactory.getConfiguration().getInterceptors().contains(interceptor)) {
                    sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
                }
            }
            return bean;
        }
    };
}

}

from pagehelper-spring-boot.

abel533 avatar abel533 commented on June 24, 2024

如果配合 通用 Mapper 使用,可以用 tk.mybatis.mapper.autoconfigure.ConfigurationCustomizer 接口,如果没用 Mapper,可以用 org 版本的。

from pagehelper-spring-boot.

suiyueqiannian avatar suiyueqiannian commented on June 24, 2024

使用了通用 Mapper 后,通用 Mapper 中排除掉了 mybatis 官方的 starter 会导致这个情况,@Configuration @ConditionalOnBean({SqlSessionFactory.class}) @EnableConfigurationProperties({PageHelperProperties.class}) @AutoConfigureAfter({MybatisAutoConfiguration.class}) public class PageHelperAutoConfiguration {
这个使用了 mybatis 官方的 MybatisAutoConfiguration

from pagehelper-spring-boot.

JR--Chen avatar JR--Chen commented on June 24, 2024

所以这个最后的解决办法是什么,我看了半天都没看明白

from pagehelper-spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.