在idea中使用 maven插件mybatis-generator自动生成mybatis配置文件

1.在pom.xml文件中添加:
<!--myibatis3 自动生成配置xml文件插件 -->
<plugins>
    <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
            <verbose>false</verbose>
            <overwrite>false</overwrite>
        </configuration>
    </plugin>
</plugins>

2.在项目src/main/resources 添加generatorConfig.xml文件,内容如下:
<!DOCTYPE generatorConfiguration PUBLIC
        "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
    <classPathEntry
            location="E:\myIdea\mylib\ojdbc6.jar"/>
    <context id="context1" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
            <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        </commentGenerator>
        <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@192.168.16.24:1522:BOCE"
                        userId="shiro" password="shiro"/>
<!-- 实体pojo路径-->
        <javaModelGenerator targetPackage="org.boce.entity"
                            targetProject="E:\projectSrc"/>
<!--生成接口路径 -->
        <sqlMapGenerator targetPackage="org.boce.mapper"
                         targetProject="E:\projectSrc"/>
<!-- 生成xml位置-->
        <javaClientGenerator targetPackage="org.boce.mapper"
                             targetProject="E:\projectSrc"
                             type="XMLMAPPER"/>
        <!-- shema 数据库 tableName表明 -->
        <table schema="shiro" tableName="demopo" />


    </context>
</generatorConfiguration>

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.配置idea:

单击右上角的“edit Configurations” 然后选中“+”,在列表中找到maven 单击,进入下图,进行配置:
Command line : mybatis-generator:generate -e






添加完成后,在又上角就可以看到。 单击运行就可以生成配置文件了。




猜你喜欢

转载自gjp014.iteye.com/blog/2381126