idea15 生成mybatis代码

pom.xml

<build>
    <finalName>mybatis_generator</finalName>
    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <dependencies>
          <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

 

src->main->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>
    <!--数据库驱动jar -->
    <!--<classPathEntry location="E:\Project\autoCode\target\mybatis-generator\WEB-INF\lib\mysql-connector-java-5.1.34.jar" />-->

    <context id="DB2Tables" targetRuntime="MyBatis3Simple">
        <!--去除注释  -->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <!--数据库连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/edu"
                        userId="root"
                        password="12345678">
        </jdbcConnection>
        <!--默认false
           Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.
         -->
        <!--<javaTypeResolver >-->
            <!--<property name="forceBigDecimals" value="false" />-->
        <!--</javaTypeResolver>-->

        <!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建  使用Maven生成在target目录下,会自动创建) -->
        <javaModelGenerator targetPackage="com.pojo" targetProject="MAVEN" >
            <!--<property name="enableSubPackages" value="false" />-->
            <!--<property name="trimStrings" value="true" />-->

        </javaModelGenerator>
        <!--生成SQLMAP文件 -->
        <sqlMapGenerator targetPackage="com.mapper"  targetProject="MAVEN">
            <property name="enableSubPackages" value="true" />

        </sqlMapGenerator>
        <!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现  context id="DB2Tables" 修改targetRuntime="MyBatis3"  -->
        <!--<javaClientGenerator type="SPRING" targetPackage="com.qianyan.persistence.dao"  targetProject="MAVEN">-->
            <!--<property name="enableSubPackages" value="false" />-->
        <!--</javaClientGenerator>-->
        <javaClientGenerator type="XMLMAPPER"  targetPackage="com.imapper" targetProject="MAVEN">
                         <property name="enableSubPackages" value="true"/>
                     </javaClientGenerator>
        <!--对应数据库表 mysql可以加入主键自增 字段命名 忽略某字段等-->

        <table tableName="t_courses" domainObjectName="TCourses"  enableSelectByPrimaryKey="true"
               enableUpdateByPrimaryKey="true"
               enableDeleteByPrimaryKey="true" enableSelectByExample="false"

               enableDeleteByExample="false" enableCountByExample="false"
               enableUpdateByExample="false">

        </table>

        <table tableName="t_courses_chapter" domainObjectName="TCoursesChapter"  enableSelectByPrimaryKey="true"
               enableUpdateByPrimaryKey="true"
               enableDeleteByPrimaryKey="true" enableSelectByExample="false"

               enableDeleteByExample="false" enableCountByExample="false"
               enableUpdateByExample="false">

        </table>

        <table tableName="t_teacher" domainObjectName="TTeacher"  enableSelectByPrimaryKey="true"
               enableUpdateByPrimaryKey="true"
               enableDeleteByPrimaryKey="true" enableSelectByExample="false"

               enableDeleteByExample="false" enableCountByExample="false"
               enableUpdateByExample="false">

        </table>

        <table tableName="t_comments" domainObjectName="TComments"  enableSelectByPrimaryKey="true"
               enableUpdateByPrimaryKey="true"
               enableDeleteByPrimaryKey="true" enableSelectByExample="false"

               enableDeleteByExample="false" enableCountByExample="false"
               enableUpdateByExample="false">

        </table>
    </context>
</generatorConfiguration>

 

然后到 maven project ->mybatis-generator ->mybatis-generator:generate 右键->run maven build 

如果没有提示错误就会在target文件中生相应的代码

posted on 2016-05-10 23:48  lvlv岁月流逝  阅读(600)  评论(0编辑  收藏  举报

导航