添加一個類,這個類用於初始化 PageInterceptor 這個類,這一次嘗試成功,正確返回分頁數據。代碼如下:
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Properties;
@Configuration
public class MyBatisPlusConfig {
/*
* 分頁插件,自動識別數據庫類型
* 多租戶,請參考官網【插件擴展】
*/
@Bean
public PaginationInnerInterceptor paginationInterceptor() {
return new PaginationInnerInterceptor();
}
@Bean
PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
properties.setProperty("helperDialect", "mysql");
pageInterceptor.setProperties(properties); // 由此可進入源碼,
return pageInterceptor;
}
}