• 记一次使用mybatis生成工具生成mapper层代码


    1. 首先要下载好两个jar包

    下载地址
    链接:https://pan.baidu.com/s/10lUtaODB8AOjdQAgXMUUFQ
    提取码:c3a2

    1. 在数据库中建立好表格

    CREATE TABLE ASSETSTATUS(
    	ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    	OWNER VARCHAR(20) NOT NULL,
    	DATASTARTTIME TIMESTAMP NOT NULL,
    	DATATHEME VARCHAR(20) NOT NULL,
    	DATASIZE VARCHAR(20) NOT NULL,
    	BLOCKVERSION VARCHAR(20) NOT NULL,
    	DATAINBLOACKID VARCHAR(20) NOT NULL,
    	ISONLINE BOOLEAN  NOT NULL
    ) DEFAULT CHARSET=UTF8;
    
    CREATE TABLE ASSETTRADING (
    	ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    	OWNER VARCHAR(20) NOT NULL,
    	USERS VARCHAR(20) NOT NULL,
    	TRADETIME VARCHAR(20) NOT NULL,
    	DATATHEME VARCHAR(20) NOT NULL,
    	DATAVALUE VARCHAR(20) NOT NULL,
    	DATASIZE VARCHAR(20) NOT NULL,
    	ISONLINE BOOLEAN NOT NULL
    	
    
    ) DEFAULT CHARSET=UTF8;
    
    
    CREATE TABLE ASSETPRICING(
    	ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    	DATACHEACKER VARCHAR(20) NOT NULL,
    	DATAPRICEDECIDETIME TIMESTAMP NOT NULL,
    	DATASIZE VARCHAR(20) NOT NULL,
    	DATAVALUE VARCHAR(20) NOT NULL,
    	ISONLINE BOOLEAN NOT NULL
    )  DEFAULT CHARSET=UTF8;
    
    
    CREATE TABLE USERS(
    	 ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    	 USERNAME VARCHAR(20) NOT NULL,
    	 PASSWORD VARCHAR(20) NOT NULL
    ) DEFAULT CHARSET=UTF8;
    
    1. 在项目目录中创建一个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:programeeclipse-javamyworkspaceDataSharePlatform-javasrcmain
    esourcesmysql-connector-java-5.0.8-bin .jar" />   
        <!-- <classPathEntry location="C:oracleproduct10.2.0db_1jdbclibojdbc14.jar" />-->  
        <context id="DB2Tables" targetRuntime="MyBatis3">  
            <commentGenerator>  
                <property name="suppressAllComments" value="true" />  
            </commentGenerator>  
            <!-- 数据库链接URL、用户名、密码 -->  
             <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:8000/datashare-platform?characterEncoding=UTF-8" userId="root" password="root">   
            <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">-->  
            </jdbcConnection>  
            <javaTypeResolver>  
                <property name="forceBigDecimals" value="false" />  
            </javaTypeResolver>  
            <!-- 生成模型的包名和位置 -->  
            <javaModelGenerator targetPackage="com.dreamcold.dreamcold.entity" targetProject="D:programeeclipse-javamyworkspaceDataSharePlatform-javasrcmainjava">
                <property name="enableSubPackages" value="true" />  
                <property name="trimStrings" value="true" />  
            </javaModelGenerator>  
            <!-- 生成的映射文件包名和位置 -->  
            <sqlMapGenerator targetPackage="com.dreamcold.dreamcold.mapper" targetProject="D:programeeclipse-javamyworkspaceDataSharePlatform-javasrcmainjava">
                <property name="enableSubPackages" value="true" />  
            </sqlMapGenerator>  
            <!-- 生成DAO的包名和位置 -->  
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.dreamcold.dreamcold.mapper" targetProject="D:programeeclipse-javamyworkspaceDataSharePlatform-javasrcmainjava">
                <property name="enableSubPackages" value="true" />  
            </javaClientGenerator>  
    		
    		<table tableName="users"
                   domainObjectName="User"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
    
            </table>
    		
    				
    		<table tableName="assetstatus"
                   domainObjectName="AssetStatus"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
    
            </table>
    		
    				
    		<table tableName="assetpricing"
                   domainObjectName="AssetPricing"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
    
            </table>
    		
    				
    		<table tableName="assettrading"
                   domainObjectName="AssetTrading"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
    
            </table>
    
        </context>  
    </generatorConfiguration> 
    
    1. 进入该目录
    cd dirname
    cd /d d: #注意换盘啊,我放在d盘要切盘
    java -jar mybatis-generator-core-1.4.0.jar -configfile generator.xml -overwrite
    
    1. 生成成功

  • 相关阅读:
    css3
    css3
    npm 安装包无法继续下载? 卡住
    tcp/ip协议中的SYN, ACK的数值变化
    【转】6 Reasons Why JavaScript’s Async/Await Blows Promises Away (Tutorial)
    ES6 中 Symbol.split的用法
    Why does Typescript use the keyword “export” to make classes and interfaces public?
    es6中的import,export浏览器已经支持
    Understanding the JavaScript Engine—— two phase
    【转】js-ES6学习笔记-Symbol
  • 原文地址:https://www.cnblogs.com/mengxiaoleng/p/13418190.html
Copyright © 2020-2023  润新知