MybatisGenerator生成SSM的dao层

官网下载

mybatis generator

下载generator的release版本mybatis-generator-core-1.4.0-bundle.zip

https://github.com/mybatis/generator/releases

mybatis generator

generator.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>  
<!-- 数据库驱动-->  
    <classPathEntry  location="D:\workspace6_5\HjzzAuthPlatform\mysql-connector-java-5.1.22-bin.jar"/>  
    <context id="DB2Tables"  targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressDate" value="true"/>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="false"/>  
        </commentGenerator>  
        <!--数据库链接URL,用户名、密码 -->  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" 
            connectionURL="jdbc:mysql://222.222.221.138:3306/authplatform?useUnicode\=true&amp;characterEncoding\=UTF-8" 
          userId="root" password="root">  
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
        <!-- 生成pojo的包名和位置-->  
        <javaModelGenerator targetPackage="com.autumn.model" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  
        <!-- 生成映射文件xml的包名和位置-->  
        <sqlMapGenerator targetPackage="com.autumn.mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  
        <!-- 生成DAO接口的包名和位置-->  
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.autumn.mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->  
        <table tableName="account" domainObjectName="Account" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="auth_role" domainObjectName="Auth_role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="auth_system" domainObjectName="Auth_system" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
    </context>  
</generatorConfiguration>

把下载的mybatis-generator-core-1.4.0.jar、generator.xml(需要指定mysql-connector-java-5.1.22-bin.jar)放入项目跟目录下面。

java命令

用java命令生成dao、mapper、pojo

java -jar mybatis-generator-core-1.4.0.jar -configfile generator.xml -overwrite

Maven

如果是maven,generator.xml放入项目下面,pom.xml中用如下配置,maven的targetProject和普通的myeclipse项目不一样,需要更改targetProject。

      <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
      </dependency>
      <plugin>
            <groupId>org.mybatis.generator</groupId>           <artifactId>mybatis-generator-maven-plugin</artifactId>           <version>1.3.2</version>     </plugin>

猜你喜欢

转载自www.cnblogs.com/aeolian/p/11981020.html