mybatis,genarate自动生成代码

---恢复内容开始---

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>
    <!--
    mvn mybatis-generator:generate -f mybatis.xml

     <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
      SELECT sys_guid() AS ID FROM DUAL
    </selectKey>
    insert into CXS
    -->
    <classPathEntry location="/Users/admin/.m2/repository/oracle/ojdbc6/1.0/ojdbc6-1.0.jar" />
    <context id="MysqlTables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:clapp"
                        userId="newapp"
                        password="newapp">
        </jdbcConnection>

        <javaTypeResolver>
            <!--长度 >18 生成 BigDecimal;-->
            <!--长度 [10,18] 生成 Long;-->
            <!--长度 [5,9] 生成 Integer;-->
            <!--长度 (0,4] 生成 Short;-->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--model对象及其example对象的位置-->
        <javaModelGenerator targetPackage="com.kaian.credit.biz.dto.apply" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--xml文件位置-->
        <sqlMapGenerator targetPackage="mybatis" targetProject="src/main/resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!--XXX-Mapper文件位置-->
        <javaClientGenerator targetPackage="com.kaian.credit.biz.dao.apply" type="XMLMAPPER" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!--数据库中的表名-->
        <table schema="NEWAPP" tableName="DA_CXS_CREDIT_TEL_OUT" domainObjectName="DaCxsCreditTelOut">

            <!--是否使用真实的列名-->
            <property name="useActualColumnNames" value="false"/>
            <property name="ignoreQualifiersAtRuntime" value="true"/>

            <!--表的列名到字段名的转换-->
            <!--<columnOverride column="create_time" property="createTime" />-->

            <!--数据库类型到类字段类型的转换-->
            <!--<columnOverride column="" javaType="Double"/>-->

        </table>

        <!-- 
        <table tableName="IMAGE_UPLOAD_CHECK_RULE" domainObjectName="ImageUploadCheckRule">
            <property name="useActualColumnNames" value="false"/>
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="IMAGE_UPLOAD_RECORD" domainObjectName="ImageUploadRecord">
            <property name="useActualColumnNames" value="false"/>
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="IMAGE_VIEW_GROUP" domainObjectName="ImageViewGroup">
            <property name="useActualColumnNames" value="false"/>
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
         -->
    </context>

</generatorConfiguration>

 

最后用maven运行这个文件即可。找到mybatis.xml,

进入mybatis本目录文件夹里面,cd credit-biz

因为这个mybatis.xml文件里有mvn导入的jar,

然后看下mybatis.xml文件里面有什么

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foxes.generate</groupId>
    <artifactId>mybatis</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>mybatis</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


    <dependencies>
        <dependency>
            <groupId>oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>1.0</version>
        </dependency>
    
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <executions>
                    <execution>
                      <id>Generate MyBatis Artifacts</id>
                      <goals>
                        <goal>generate</goal>
                      </goals>
                    </execution>
                  </executions>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

 

最后运行下面这个即可:

mvn mybatis-generator:generate -f mybatis.xml

 

 

 

---恢复内容结束---

posted @ 2017-07-18 14:44  ctgu_czy  阅读(994)  评论(0编辑  收藏