Springboot整合MybatisPlus的实现过程
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要介绍"Springboot整合MybatisPlus的实现过程",在日常操作中,相信很多人在Springboot整合MybatisPlus的实现过程问题上存在疑惑,小编查阅了各式资料,整理
千家信息网最后更新 2026年11月01日Springboot整合MybatisPlus的实现过程
这篇文章主要介绍"Springboot整合MybatisPlus的实现过程",在日常操作中,相信很多人在Springboot整合MybatisPlus的实现过程问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"Springboot整合MybatisPlus的实现过程"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
1、pom文件
4.0.0 com.cun plus 0.0.1-SNAPSHOT jar plus Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.14.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test com.baomidou mybatis-plus-boot-starter 2.3 org.freemarker freemarker 2.3.28 com.alibaba druid-spring-boot-starter 1.1.10 org.springframework.boot spring-boot-maven-plugin
2、创建CodeGenerator.java
package com.cun.plus;import com.baomidou.mybatisplus.enums.IdType;import com.baomidou.mybatisplus.generator.AutoGenerator;import com.baomidou.mybatisplus.generator.config.DataSourceConfig;import com.baomidou.mybatisplus.generator.config.GlobalConfig;import com.baomidou.mybatisplus.generator.config.PackageConfig;import com.baomidou.mybatisplus.generator.config.StrategyConfig;import com.baomidou.mybatisplus.generator.config.rules.DbType;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;public class CodeGenerator { public static void main(String[] args) { //1. 全局配置 GlobalConfig config = new GlobalConfig(); config.setActiveRecord(false) // 是否支持AR模式 .setAuthor("len") // 作者 .setOutputDir(".\\src\\main\\java") // 生成路径 .setFileOverride(true) // 文件覆盖 .setIdType(IdType.AUTO) // 主键策略 .setServiceName("I%sService") // 设置生成的service接口的名字的首字母是否为I // IUserService .setBaseResultMap(true) .setBaseColumnList(true); //2. 数据源配置 DataSourceConfig dsConfig = new DataSourceConfig(); dsConfig.setDbType(DbType.MYSQL) // 设置数据库类型 .setDriverName("com.mysql.jdbc.Driver") .setUrl("jdbc:mysql://localhost:3306/mydatab?useSSL=true&verifyServerCertificate=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8") .setUsername("root") .setPassword("lqq74561"); //3. 策略配置 //配置要生成的表的表名 String[] tableName = {"system_power_type","system_admin","company","power_api","power_action","power_action_api","power_action_group","power_admin_group","power_group"}; StrategyConfig stConfig = new StrategyConfig(); stConfig.setCapitalMode(true) //全局大写命名 .setDbColumnUnderline(true) // 指定表名 字段名是否使用下划线 .setNaming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略 .setTablePrefix("tb_") .setInclude(tableName); // 生成的表 //4. 包名策略配置 PackageConfig pkConfig = new PackageConfig(); pkConfig.setParent("com.cun.plus") .setMapper("mapper") .setService("service") .setController("controller") .setEntity("entity") .setXml("mapper"); //5. 整合配置 AutoGenerator ag = new AutoGenerator(); ag.setGlobalConfig(config) .setDataSource(dsConfig) .setStrategy(stConfig) .setPackageInfo(pkConfig); //6. 执行 ag.setTemplateEngine(new FreemarkerTemplateEngine()); ag.execute(); }}3、在application.yml中配置mybatis-plus
#mybatis-plusmybatis-plus: #xml mapper-locations: classpath:/mapper/*Mapper.xml #bean typeAliasesPackage: com.cun.plus.entity global-config: # 3:"UUID"; id-type: 3 field-strategy: 2 db-column-underline: true key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator logic-delete-value: 1 logic-not-delete-value: 0 sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector configuration: map-underscore-to-camel-case: true cache-enabled: false #JdbcTypeForNull jdbc-type-for-null: 'null'
4、创建MybatisPlusConfig.java文件
package com.cun.plus.conf;import org.mybatis.spring.annotation.MapperScan;import org.springframework.context.annotation.Configuration;@Configuration@MapperScan("com.cun.plus.mapper")public class MybatisPlusConfig {}其他
Wrapper:MP内置条件封装器。
Sql分析器:(MybatisPlusConfig.java中)
/** * SQL执行效率插件 */@Bean@Profile({"dev","test"})// 设置 dev test 环境开启public PerformanceInterceptor performanceInterceptor() { return new PerformanceInterceptor();}
到此,关于"Springboot整合MybatisPlus的实现过程"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
配置
整合
过程
策略
学习
生成
数据
文件
全局
数据库
更多
UTF-8
帮助
实用
接下来
下划线
作者
分析器
名字
大写
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网与科技
互联网科技公司起名
互联网金融监管科技数据
卓越科技(互联网 )
电子科技大学互联网
互联网科技logo
济南和联互联网科技有限公司
996高科技互联网公司
迪庆互联网科技招生
互联网科技创新的路径
互联网科技大赛获奖感言
保险科技服务互联网营销体系
富国互联网金融科技混合基金
科技互联网行业投资研究
互联网时代科技型公司的机会
互联网科技机房
求路客互联网科技电话
互联网科技创新方面的资料
六子台科技互联网展会
颐高云石互联网科技
上海睿民互联网科技有限公司
互联网科技有限公司图片
互联网科技媒体
亿账通互联网科技
菲比寻常互联网科技
剑昆互联网络科技有限公司临桂
银川新华互联网科技职业技术培训学校图片
重庆互联网医院沙龙医盟信息科技
福州德业互联网科技
唐山双旺合互联网科技产业园