Intellij IDEA 14中使用MyBatis generator 自动生成MyBatis代码

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

Intellij IDEA 14 作为Java IDE 神器,接触后发现,非常好用,对它爱不释手,打算离开eclipse和myeclipse,投入Intellij IDEA的怀抱。

     然而在使用的过程中会发现Intellij IDEA也有一些不尽如意的地方,难免会有些不爽:Intellij IDEA 的插件库远不及eclipse的丰富。 mybatis-generator在eclipse中有专门的插件,而没有开发出Intellij IDEA能够使用的插件。

    不过不用灰心,如果你的项目是使用maven组织的,那么我们可以在Intellij IDEA中使用 mybatis-generator-maven-plugin插件来完成MyBatis model 和Mapper文件的自动生成。


STEP 0.在Intellij IDEA创建maven项目(本过程比较简单,略)


STEP 1. 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <build>  
  2.   <finalName>xxx</finalName>  
  3.   <plugins>  
  4.     <plugin>  
  5.       <groupId>org.mybatis.generator</groupId>  
  6.       <artifactId>mybatis-generator-maven-plugin</artifactId>  
  7.       <version>1.3.2</version>  
  8.       <configuration>  
  9.         <verbose>true</verbose>  
  10.         <overwrite>true</overwrite>  
  11.       </configuration>  
  12.     </plugin>  
  13.   </plugins>  
  14. </build>  


STEP 2. 在maven项目下的src/main/resources 目录下建立名为 generatorConfig.xml的配置文件,作为mybatis-generator-maven-plugin 插件的执行目标,模板如下:


[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE generatorConfiguration  
  3.         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  4.         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  
  5. <generatorConfiguration>  
  6.     <!--导入属性配置 -->  
  7.     <properties resource="generator.properties"></properties>  
  8.   
  9.     <!--指定特定数据库的jdbc驱动jar包的位置 -->  
  10.     <classPathEntry location="${jdbc.driverLocation}"/>  
  11.   
  12.     <context id="default" targetRuntime="MyBatis3">  
  13.   
  14.   
  15.         <!-- optional,旨在创建class时,对注释进行控制 -->  
  16.         <commentGenerator>  
  17.             <property name="suppressDate" value="true" />  
  18.         </commentGenerator>  
  19.   
  20.   
  21.         <!--jdbc的数据库连接 -->  
  22.         <

猜你喜欢

转载自blog.csdn.net/hgffhh/article/details/83759680
今日推荐