spring boot 中使用mybatis自动生成mapper和dao插件
mybatis自动生成插件(mybatis-generator)可以自动生成xml文件和dao文件。这样就大大减少了我们重复编码工作。只需要把精力集中在核心业务上面。
使用编辑器是idea,这里默认假设已经把spring boot和mybaits整合好的。如果没有可以参见:《spring boot 2.x 整合mybaits及分页插件》文章。
步骤:
1:在pom.xml中添加mybatis-generator插件
2:添加插件需要的配置文件
3:在idea中配置
4:编码测试
一:pom.xml中添加插件
在pom.xml的plugins节点中添加mybatis插件
<!-- 添加mybatis 自动生成插件--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin> |
说明:
二:添加自动生产配置文件。
根据pom.xml文件中配置的路径创建generatorConfig.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBati 原创不易,完成人机校验,阅读全文 相关推荐GIT项目人人自动生成:renren-generatorAI编程Trae中使用spring boot启动失败处理GIT项目【SpringBootFrame】springboot集成mybatis、redis、shiro、druid、通用mapper、分页插件、swagger框架资源我收集了 12 款自动生成器,效果太逆天GIT项目spring boot整合mybatis+durid+事务+PageHelper分页插件+sql打印的整合经验分享spring boot整合pagehelper分页插件学习笔录-SPRING BOOTspring boot 测试插件使用及result风格实例1&打包启动.学习笔录-SPRING BOOTspring boot自动注解引发的错误 |