mybits根据表自动生成 java类和mapper 文件 mybits根据表自动生成 java类和mapper 文件
我这个脑子啊,每次创建新的工程都会忘记是怎么集成mybits怎么生成mapper文件的,so today , I can't write this blog for myself.
NO.1 we should create table on the database.
eg.user
CREATE TABLE `t_users` ( `uid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'PRK', `username` varchar(32) DEFAULT NULL COMMENT '用户名', `password` varchar(128) DEFAULT NULL COMMENT '密码', `email` varchar(64) DEFAULT NULL COMMENT '邮箱', `crtime` datetime DEFAULT NULL COMMENT '创建时间', PRIMARY KEY (`uid`), UNIQUE KEY `name` (`username`), UNIQUE KEY `mail` (`email`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
NO.2 我们应该在我们的项目中添加自动生成代码的xml 和 pom 文件中加入配置 前提是mybits需要引入啊
1.pom文件中
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<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>
</plugin>
</plugins>
</build>
2.配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
<classPathEntry location="F:softapache-maven-3.5.2mvnRepositorymysqlmysql-connector-java5.1.37mysql-connector-java-5.1.37.jar"/>
<context ></table>
</context>
</generatorConfiguration>
NO.3 IDEA配置
Run/Debug Configurations
Maven - Command line mybatis-generator:generate -e
NO.4 Just Run It ;