手把手教你如何通过general自动创建mybati中mapper映射接口以及bean

在网上查了下如何自动实现mybatis的中mapper以及映射接口和bean,感觉不是挺适合新手的,而且说的模棱两可,介于此,我就自己写一篇记录,日后忘记了便于翻阅。

我们都知道,mybatis要手动配置那些文件,有时弄不好会出错,我刚开始学的时候深有体会,如今春天来了,废话不多说,入正题。这个是lib里面的结构

这里最重要的是是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>  
<!-- 数据库驱动-->  
<!-- 可以根据自己的情况而补加架包,这个架包是放在lib目录下的。-->  
    <classPathEntry  location="ojdbc5.jar"/>  
    <context id="DB2Tables"  targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressDate" value="true"/>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  
        <!--数据库链接URL,用户名、密码 -->  
           <!-- 根据自己的情况而定-->  
        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="scott" password="tiger">  
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
        <!-- 生成模型的包名和位置-->  
 <!-- 根据自己的情况而生成包名-->  
        <javaModelGenerator targetPackage="com.shandian.bean" targetProject="src/main/java">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  
        <!-- 生成映射文件的包名和位置-->  
        <sqlMapGenerator targetPackage="com.shandian.mapping" targetProject="src/main/java">  
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  
        <!-- 生成DAO的包名和位置-->  
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.shandian.Dao" targetProject="src/main/java">  
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>  
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> 
	<!--一张表对应一个table-->   
        <table tableName="Emp" domainObjectName="Emp" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="Dept" domainObjectName="Dept" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>  
</generatorConfiguration>  


首先你们到我的度盘中吧这个下下来解压放到你喜欢的盘下,链接: https://pan.baidu.com/s/1o8wLXwe 密码: iz4t,

然后通过doc命令进入lib目录下,然后将这个命令拷贝到如下。java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite



回车,最后你会看到

此时说明你成功了,接下来进入到lib下面的src目录下看有没有你所需要的mapper以及接口映射和bean


现在你可以去嗨皮你的mybatis了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值