mybatis-plus的整合與使用
Mybatis-Plus:
Mybatis-Plus(簡稱MP)是一個 Mybatis 的增強工具,在 Mybatis 的基礎上只做增強不做改變,為簡化開發、提高效率而生。
核心功能:
程式碼生成器、CRUD介面、條件構造器以及內建了一些實用的外掛
springboot整合:
POM依賴
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatisplus-spring-boot-starter</artifactId> <version>1.0.5</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.3.3</version> </dependency>
配置
###mybatis-plus配置 #MyBatis 配置檔案位置 mybatis-plus.config-location=classpath:mybatis-config.xml #Maven 多模組專案的掃描路徑需以 classpath*: 開頭 (即載入多個 jar 包下的 XML 檔案) mybatis-plus.mapper-locations=classpath*:mybatis/*.xml #啟動時是否檢查 MyBatis XML 檔案的存在,預設不檢查。 mybatis-plus.check-config-location=false #指定 MyBatis 的執行器,MyBatis 的執行器 #MyBatis 的執行器總共有三種: #ExecutorType.SIMPLE:該執行器型別不做特殊的事情,為每個語句的執行建立一個新的預處理語句(PreparedStatement) #ExecutorType.REUSE:該執行器型別會複用預處理語句(PreparedStatement) #ExecutorType.BATCH:該執行器型別會批量執行所有的更新語句 mybatis-plus.executor-type=simple #是否開啟自動駝峰命名規則(camel case)對映 mybatis-plus.configuration.map-underscore-to-camel-case=true ###全域性策略配置 #Mapper 對應的 XML 檔案會自動重新整理,更改 XML 檔案後,無需再次重啟工程,生產環境無需開啟 mybatis-plus.global-config.refresh=true #是否快取 Sql 解析,預設不快取。 mybatis-plus.global-config.sql-parser-cache=true #表名字首 mybatis-plus.global-config.db-config.table-prefix=T_