MybatisPlus3.5.5與pagehelper?starter2.1.0沖突的問題解決
問題說明
MybatisPlus3.5.5與pagehelper starter2.1.0同時引用了jsqlparser4.6和4.7在idea中使用并不會報錯,打包之后用jar運行便會出現(xiàn)錯誤
- 如果以jsqlparser4.7版本為準,啟動項目都起不起來,原因是jsqlparser4.7版本中把版本4.6的一個類被干掉了
- 如果以jsqlparser4.6版本為準,啟動可以成功,但是查詢會有問題
解決方案
首先確認兩個依賴的版本號為3.5.5 和 2.1.0
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>2.1.0</version> <exclusions> <exclusion> <groupid>com.github.jsqlparser</groupid> <artifactId>jsqlparser</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.5</version> <exclusions> <exclusion> <groupid>com.github.jsqlparser</groupid> <artifactId>jsqlparser</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>sqlparser4.5</artifactId> <version>6.1.0</version> </dependency>
建立兩個類
import com.github.pagehelper.dialect.helper.MySqlDialect; import com.github.pagehelper.parser.CountJSqlParser45; import com.github.pagehelper.parser.CountSqlParser; import com.github.pagehelper.parser.OrderByJSqlParser45; import com.github.pagehelper.parser.OrderBySqlParser; import com.github.pagehelper.util.ClassUtil; import java.util.Properties; /** * 解決Mybatis Plus與PageHelper之間的沖突 * 覆蓋父類 {@link com.github.pagehelper.dialect.AbstractDialect} 中的setProperties方法, * 將CountJSqlParser45、OrderByJSqlParser45提供的兩個類來替換掉Default類 * * @Author zsp * @Date 2024/7/9 **/ public class LocalMySqlDialect extends MySqlDialect { @Override public void setProperties(Properties properties) { this.countSqlParser = ClassUtil.newInstance(properties.getProperty("countSqlParser"), CountSqlParser.class, properties, CountJSqlParser45::new); this.orderBySqlParser = ClassUtil.newInstance(properties.getProperty("orderBySqlParser"), OrderBySqlParser.class, properties, OrderByJSqlParser45::new); } }
import com.github.pagehelper.page.PageAutoDialect; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; /** * 在spring boot啟動完成后將LocalMySqlDialect注冊進pagehelper * * @Author zsp * @Date 2024/7/9 **/ @Component public class DialectInit implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { PageAutoDialect.registerDialectAlias("mysql", LocalMySqlDialect.class); } }
原理
PageAutoDialect這個類是用來管理注冊方言的,它在MySql的方言中默認使用了com.github.pagehelper.dialect.helper.MySqlDialect
類,而MySqlDialect
類繼承自com.github.pagehelper.dialect.AbstractDialect
類,而AbstractDialect
默認實現(xiàn)了setProperties
方法,我們覆蓋掉這個方法,使用官方提供的4.5兼容包,并重新注冊即可。
到此這篇關(guān)于MybatisPlus3.5.5與pagehelper starter2.1.0沖突的問題解決的文章就介紹到這了,更多相關(guān)MybatisPlus3.5.5與pagehelper starter2.1.0沖突內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
netflix.discovery.shared.transport.TransportException:Cannot
這篇文章主要介紹了netflix.discovery.shared.transport.TransportException:Cannot execute request on any known server報錯問題及解決方法,感興趣的朋友一起看看吧2023-09-09如何解決zookeeper集群重啟Error contacting service.It
本文詳細介紹了Zookeeper集群啟動異常的排查步驟,包括網(wǎng)絡(luò)問題、防火墻配置、Java環(huán)境、端口占用、網(wǎng)卡問題、網(wǎng)絡(luò)問題以及節(jié)點配置信息的檢查,通過逐一排查和解決這些問題,可以有效地啟動Zookeeper集群2024-12-12java注解實現(xiàn)websocket服務(wù)的兩種方式
Java WebSocket是一種基于TCP協(xié)議的雙向全雙工消息傳輸技術(shù),它允許服務(wù)器和客戶端之間實時通信,具有低延遲和高效率的特點,下面這篇文章主要給大家介紹了關(guān)于java注解實現(xiàn)websocket服務(wù)的兩種方式,需要的朋友可以參考下2024-08-08一篇文章帶你了解SpringMVC數(shù)據(jù)綁定
這篇文章主要給大家介紹了關(guān)于如何通過一篇文章弄懂Spring MVC的參數(shù)綁定,文中通過示例代碼以及圖文介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2021-08-08IDEA POM文件配置profile實現(xiàn)不同環(huán)境切換的方法步驟
這篇文章主要介紹了IDEA POM文件配置profile實現(xiàn)不同環(huán)境切換的方法步驟2024-03-03