SSM使用MybatisGenerator生成dao层

官网下载

mybatis

https://mybatis.org/

或者去github上下载

mybatis generator

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

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

SSM

构建基础spring mvc

https://www.cnblogs.com/aeolian/p/11950980.html

整合Mybatis

除了mybatis官网下的mybatis-3.5.3.jar

还需要mybatis-spring-2.0.3.jar

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.mapping" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO接口的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.autumn.dao" 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命令生成dao、mapper、pojo

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

猜你喜欢

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