mybatis自动生成SQL

基于MAVEN,让mybatis自动生成SQL语句。先添加插件依赖:

<build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

然后写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>
    <!--mysql的jar包路径-->
    <classPathEntry location="F:\Repositories\Maven\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar"/>

    <context id="default" targetRuntime="MyBatis3">

        <property name="javaFileEncoding" value="utf-8"/>

        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
            <property name="useActualColumnNames" value="true" />
        </commentGenerator>

        <!--数据库连接参数-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/smbms"
                        userId="root"
                        password="wjb"/>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="true"/>
        </javaTypeResolver>

        <!--生成pojo实体类,targetPackage指定包名,targetProject指定路径-->
        <javaModelGenerator targetPackage="pojo" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--生成mapper.xml-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--生成mapper-->
        <javaClientGenerator targetPackage="mapper" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--对哪张表做操作-->
        <table tableName="smbms_user" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>

    </context>
</generatorConfiguration>

 

posted on 2017-01-17 14:28  三碗才能饱  阅读(1996)  评论(0编辑  收藏  举报

导航