mybatis逆向生成实体类,maven方式
1.pom文件
虽然pom文件中的<dependency>依赖中已经有了mysql驱动包,但在 <plugin>插件中,必须再引入mysql-connector-java,再加上mybatis-generator-core和mybatis包.。由于原先的pom文件中有spring-boot-maven-plugin插件(springboot项目),所以用<pluginManagement>将插件包起来
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>generator.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
2.generator.xml
<?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>
<context id="MyBatis3Simple" targetRuntime="MyBatis3Simple"
defaultModelType="flat">
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/focus?useUnicode=true&characterEncoding=utf8&useSSL=false"
userId="root" password="root" />
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.melo.focus.domain.basic"
targetProject="MAVEN" />
<sqlMapGenerator targetPackage="mapper/basic"
targetProject="MAVEN" />
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.melo.focus.mapper.basic"
targetProject="MAVEN" />
<table domainObjectName="User" tableName="user"></table>
<table domainObjectName="Role" tableName="role"></table>
<table domainObjectName="Resource" tableName="resource"></table>
<table domainObjectName="Authority" tableName="authority"></table>
<table domainObjectName="ResourceAuthority" tableName="resouce_authority"></table>
<table domainObjectName="RoleResourcer" tableName="role_resource_r"></table>
<table domainObjectName="RoleBusiness" tableName="role_business"></table>
<table domainObjectName="UserRoleR" tableName="user_role_r"></table>
</context>
</generatorConfiguration>
3.mvn mybatis-generator:generate
注意
最近发现个问题,springboot项目中 用<pluginManagement>标签,会打包失败,打出的包不能运行。将此标签注释包就可以运行了,目前不是很明白问题的原因