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&amp;characterEncoding=utf8&amp;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>标签,会打包失败,打出的包不能运行。将此标签注释包就可以运行了,目前不是很明白问题的原因

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值