案例一
- demo为
chenx/mybatisplus-demo
- 参考
- 案例
- 项目初始结构

- 数据库新建表


- 项目配置


- 启动CodeGenerator类中的main方式,输入表名,生成代码

案例二
- demo为
chenx/mybatisplus-demo1
- 参考
- 案例
- 新建1个spring boot项目,导入如下依赖
点击查看详情
| <dependencies> |
| |
| <dependency> |
| <groupId>com.baomidou</groupId> |
| <artifactId>mybatis-plus-generator</artifactId> |
| <version>3.5.1</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>org.freemarker</groupId> |
| <artifactId>freemarker</artifactId> |
| </dependency> |
| <dependency> |
| <groupId>org.apache.velocity</groupId> |
| <artifactId>velocity-engine-core</artifactId> |
| <version>2.1</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>io.swagger</groupId> |
| <artifactId>swagger-annotations</artifactId> |
| <version>1.5.20</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>mysql</groupId> |
| <artifactId>mysql-connector-java</artifactId> |
| <scope>runtime</scope> |
| </dependency> |
| |
| <dependency> |
| <groupId>com.baomidou</groupId> |
| <artifactId>mybatis-plus-boot-starter</artifactId> |
| <version>3.4.3.4</version> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-web</artifactId> |
| </dependency> |
| <dependency> |
| <groupId>org.projectlombok</groupId> |
| <artifactId>lombok</artifactId> |
| <optional>true</optional> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-test</artifactId> |
| <scope>test</scope> |
| </dependency> |
| </dependencies> |
| |
| <build> |
| <plugins> |
| |
| <plugin> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-maven-plugin</artifactId> |
| <configuration> |
| <excludes> |
| <exclude> |
| <groupId>org.projectlombok</groupId> |
| <artifactId>lombok</artifactId> |
| </exclude> |
| </excludes> |
| </configuration> |
| </plugin> |
| |
| <plugin> |
| <groupId>org.apache.maven.plugins</groupId> |
| <artifactId>maven-compiler-plugin</artifactId> |
| <version>3.8.1</version> |
| <configuration> |
| <source>1.8</source> |
| <target>1.8</target> |
| </configuration> |
| </plugin> |
| <plugin> |
| <groupId>org.apache.maven.plugins</groupId> |
| <artifactId>maven-resources-plugin</artifactId> |
| <version>3.1.0</version> |
| </plugin> |
| <plugin> |
| <groupId>org.apache.maven.plugins</groupId> |
| <artifactId>maven-surefire-plugin</artifactId> |
| <version>2.22.1</version> |
| <configuration> |
| <skipTests>true</skipTests> |
| </configuration> |
| </plugin> |
| </plugins> |
| </build> |
| |
| |
| spring.datasource.username=root |
| spring.datasource.password=123456 |
| spring.datasource.url=jdbc:mysql://192.168.0.102:3306/dbtest |
| spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver |
| |
| mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl |
| |
| |
| |
| |
| |
| mybatis-plus.global-config.db-config.logic-delete-value=1 |
| |
| mybatis-plus.global-config.db-config.logic-not-delete-value=0 |
- 编写测试类

- 测试类中需要注意的配置


- 新建数据库并任意新建几张表

- 右键运行,自动生成代码

案例三
- demo为
chenx/mybatis-geneator
- 案例
修改配置

指定对应的表名

generatorConfig.xml的绝对路径

配置application.yml

运行MybatisGeneratorMain类自动生成代码

如果希望实体类中不生成不生成xxxExample,需要在generatorConfig.xml中这样配置表名
| <table tableName="user" domainObjectName="User" |
| enableCountByExample="false" enableUpdateByExample="false" |
| enableDeleteByExample="false" enableSelectByExample="false" |
| selectByExampleQueryId="false"> |
| </table> |
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术