maven插件mybatis-generator自动生成

1、新建一个maven项目在pom.xml添加如下:

[html]  view plain  copy
  1. <plugins>  
  2.     <plugin>  
  3.                 <groupId>org.mybatis.generator</groupId>  
  4.                 <artifactId>mybatis-generator-maven-plugin</artifactId>  
  5.                 <version>1.3.2</version>  
  6.                 <configuration>  
  7.                     <verbose>false</verbose>  
  8.                     <overwrite>false</overwrite>  
  9.                 </configuration>  
  10.             </plugin>  
  11.     </plugins>  

如果以上插件还无法生成将插件这样添加【如上也可不用删除】

[html]  view plain  copy
  1.          <dependency>  
  2.     <groupId>org.mybatis.generator</groupId>  
  3.     <artifactId>mybatis-generator-maven-plugin</artifactId>  
  4.     <version>1.3.2</version>  
  5. </dependency>  


2、在项目src/main/resources 添加generatorConfig.xml文件



generatorConfig.xml 内容:

[html]  view plain  copy
  1. <span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE generatorConfiguration PUBLIC   
  3. "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  4.  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >  
  5. <generatorConfiguration>  
  6.     <classPathEntry  
  7.         location="E:\Eclipse\Repository\mysql\mysql-connector-java\5.1.29\mysql-connector-java-5.1.29.jar" />  
  8.         <context id="context1" targetRuntime="MyBatis3">  
  9.         <commentGenerator>   
  10.         <!-- 是否去除自动生成的注释 true:是 : false:否 -->   
  11.         <property name="suppressAllComments" value="true" />   
  12.         <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->   
  13.       </commentGenerator>   
  14.         <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
  15.             connectionURL="jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8"  
  16.             userId="root" password="123456" />  
  17.         <javaModelGenerator targetPackage="org.share.domain.tree.entity"  
  18.             targetProject="E:\workspace\share\share-domain\src\main\java" />  
  19.         <sqlMapGenerator targetPackage="org.share.domain.tree.mapper"  
  20.             targetProject="E:\workspace\share\share-domain\src\main\java" />  
  21.         <javaClientGenerator targetPackage="org.share.domain.tree.mapper"  
  22.             targetProject="E:\workspace\share\share-domain\src\main\java" type="XMLMAPPER" />  
  23.         <!-- shema 数据库 tableName表明 -->  
  24.          <table schema="data" tableName="tree" />  
  25.           
  26.     </context>  
  27. </generatorConfiguration></span>  

table其他属性: 
enableCountByExample="false" 
enableUpdateByExample="false" 
enableDeleteByExample="false" 
enableSelectByExample="false" 
selectByExampleQueryId="false" 
schema即为数据库名, tableName为对应的数据库表, domainObjectName是要生成的实体类, 
如果想要mapper配置文件加入sql的where条件查询, 可以将enableCountByExample等设为true, 
这样就会生成一个对应domainObjectName的Example类, enableCountByExample等设为false时, 
就不会生成对应的Example类了. 


3、选择项目中的pom.xml配置文件 右键run --》maven bulid --》在对话框中的Goals 输入mybatis-generator:generate 如图




4、刷新项目src目录就可以看到映射的xml 和接口文件了 哈哈哈  祝你好运


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值