`

Mybatis在IDEA中使用generator逆向工程生成pojo,mapper

阅读更多

1.创建maven 工程,修改pom.xml

 

 

<build>
        <plugins>
            <!-- mybatis逆向工程 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <!--配置文件的位置-->
                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
              </plugin>
         </plugins>
    </build>

 

 

2.在resources下新建   Personal-DB.propertie(数据库连接文件) (也可以写死)

   

jdbc.driverLocation=D:\\maven\\com\\oracle\\ojdbc14\\10.2.0.4.0\\ojdbc14-10.2.0.4.0.jar  
jdbc.driverClass=oracle.jdbc.driver.OracleDriver  
jdbc.connectionURL=jdbc:oracle:thin:@//localhost:1521/XE  
jdbc.userId=LOUIS  
jdbc.password=123456  

 

  

 

3.在resources下新建   generatorConfig.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>
    <properties resource="Personal-DB.properties"></properties>
    <classPathEntry location="${jdbc.driverLocation}" />
    <!--classPathEntry location="D:\zngkpt\m2\repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar" /-->
    <context id="context1" targetRuntime="MyBatis3">

        <commentGenerator>
            <!-- 去除自动生成的注释 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        
        <!-- 数据库连接配置 -->
        <jdbcConnection driverClass="${jdbc.driverClass}"
            connectionURL="${jdbc.connectionURL}"
            userId="${jdbc.userId}"
            password="${jdbc.password}" />
        <!--jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test"
                        userId="root"
                        password="mysql" /-->

 <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--配置生成的实体包
            targetPackage:生成的实体包位置,默认存放在src目录下
            targetProject:目标工程名
         -->
        <javaModelGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.pojo"
            targetProject="src/main/java" />
            
        <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
        <sqlMapGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.mapper" targetProject="src/main/java" />

         <!-- mapper方法层,默认存放在src目录下 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.bldz.train.mapper" targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 配置表 
            schema:不用填写
            tableName: 表名
            enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
            去除自动生成的例子
        -->
        <table schema="" tableName="sys_role" enableCountByExample="false" enableSelectByExample="false"
            enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="sys_permission" enableCountByExample="false" enableSelectByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="sys_role_permission" enableCountByExample="false" enableSelectByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="sys_user" enableCountByExample="false" enableSelectByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="sys_user_role" enableCountByExample="false" enableSelectByExample="false"
        enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="unit_info" enableCountByExample="false" enableSelectByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
        <table schema="" tableName="unit_type" enableCountByExample="false" enableSelectByExample="false"
               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
        </table>
    </context>
</generatorConfiguration>

 

 

3,到现在为止,所有的mybatis配置工作已经结束了,开始配置idea来运行生成pojo吧

点击菜单Run->Edit Configuration,然后在弹出窗体的左上角,如下,输入 mybatis-generator:generate -e

然后点击确定

 

 

 4.运行刚才编辑的maven,不出意外就会生成成功

 

  

 

 补充:最终 红色部分会生成 xml  对应method 的 mapper.java 文件 

 

 

转载:

    http://www.cnblogs.com/ningheshutong/p/6376970.html

 

 

 


 

  • 大小: 41.5 KB
  • 大小: 19 KB
分享到:
评论

相关推荐

    通过mybatis generator反向工程生成pojo及mapper类 带序列化插件

    通过工具类生成数据库表对应的pojo及mapper类,pojo类自带序列化

    mybatis逆向工程

    mybatis官方提供的mybatis-generator生成pojo、mapper接口及映射文件。可以将生成的pojo放到对应的pojo工程中。 将mapper接口及映射文件放到对应的dao工程中。

    mybatis-generator 逆向工程工具

    mybatis 数据库逆向生成工具,根据数据库表自动生成对应的pojo类,dao,mapper

    IDEA中MyBatis逆向工程.txt

     当数据库表比较多的时候,重复的创建pojo对象和简单的数据库表的(CRUD)操作的mapper,效率低,官方给出了使用mybatis Generator用来根据数据库表逆向生成pojo和mapper文件,极大的方便开发。

    mybatis_generator_逆向工程

    这是mybatis逆向工程包,可以针对数据库表自动生成mybatis执行所需要的Pojo、Mapper xml文件、Mapper Interface接口文件。其外这个压缩包还包含mybatis_generator_逆向工程所需的jar包和generatorConfig.xml配置文件...

    mybatis-generator生成带中文注释POJO类的超详细教程含代码和图解

    mybatis-generator自动生成带中文注释POJO类和增删改查,idea和eclipes都可以使用

    含 log4j2 日志的 mybatis-generator 逆向工程代码

    含 log4j2 日志的 mybatis-generator 逆向工程代码,减少手动写 mapper 和 pojo(bean)代码。

    mybatis-generator-gui.zip

    之所以强调单表两个字,是因为Mybatis逆向工程生成的Mapper所进行的操作都是针对单表的,也许你可能会觉得那这就有点鸡肋了,但是在大型项目中,很少有复杂的多表关联查询,所以作用还是很大的。

    mybatis-generator1.3.2工程包

    mybatis官方提供了一个叫做mybatis-generator的包,可以对数据库表进行逆向自动生成mybatis执行所需要的Pojo、Mapper.xml、Mapper Interface文件。

    Mybatis逆向工程

    1.生成的mapper.xml文件中使用4个空格来缩进 2.生成的mapper.xml文件中每个元素间增加一空行,如insert,update,delete等之间增加一空行 3.去掉*mapper.xml文件中生成的注释 4.根据数据库表名及字段的注释为Java类、...

    mybatis-generator.rar

    mybatis逆向工程生成代码,导入idea中,然后修改数据库链接地址、账号密码、指定生成表,然后运行maven插件即可生成mapper,pojo,dao

    mybatis_tools mybatis自动生成mapper 和 bean的工具

    Mybatis-Generator 为我们生成的代码非常的复杂,所以我们自己写了mybatis_tools来生成我们的mapper pojo dao service 和action。 现在开源出来给大家使用,如果您想使用此源码来生成自己的代码,但是又弄不懂怎么用...

    mybatis generator(mybatis 代码生成器,包含doc包,源码包)

    mybatis generator mybatis代码生成器 可以通过数据库生成pojo(model)类,mapper映射xml,以及生成现类的接口.资源里包含该工具所需要的核心jar包,doc包,以及源码包.别外再目录doc&gt;html&gt;index.html中还有...

    mybatis-generator-core-1.3.2

    Mybatis-Generator是一个用于自动生成dao层接口、pojo以及mapper xml的一个Mybatis插件,该插件有三种用法:命令行运行、Eclipse插件、maven插件。个人觉得maven插件最方便,可以在eclipse/intellij idea等ide上通用...

    springboot+mybatis3+druid+postgresql

    springboot+druid+mybatis+postgresql框架搭建,使用mybatis-generator自动生成pojo+mapper+dao

    Maven项目逆向生成工具 自动生成数据库表的pojo对象以及mapper文件 可以免费下载无需付费

    需要在项目pom文件的插件节点里面加上逆向生成插件 将配置文件放在项目根目录 &lt;!--mybatis逆向生成插件--&gt; &lt;groupId&gt;org.mybatis.generator &lt;artifactId&gt;mybatis-generator-maven-plugin &lt;version&gt;1.3.6 &lt;!--...

    mybatis-generator-1.35-master.zip

    mybatis-generator --------------------------逆向生成工具 通过生成pojo、dao、Mapper

    MyBatis 框架的代码生成工具

    自动生成 Mapper 接口:MyBatis Generator 可以生成与数据库表对应的 Mapper 接口,该接口中定义了与数据库表相关的增删改查操作方法。 自动生成 XML 映射文件:MyBatis Generator 会根据数据库表结构自动生成对应...

    mybatis代码生成器(支持mysql和sqlServer)

    mybatis代码自动生成器,在generatorConfig.xml中配置好数据库连接和表名,进入解压后的目录运行如下命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite 即可自动生成...

Global site tag (gtag.js) - Google Analytics