mybatis的generator的使用问题(亲测通过)

来源:互联网 发布:linux split 编辑:程序博客网 时间:2024/04/30 03:29

这是我公司项目里使用经历,所以是可用的,不是在哪里拿来的。

我的是mysql5.6数据库,win10系统,Eclipse IDE Mars2,

安装mybatis-generator过程不说,我的博客有两篇文章专门讲这个的,是我亲身经历的,可以去参考。

直接上最复杂的配置过程: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>
<classPathEntry location="E:/jars/mysql-connector-java-5.1.23-bin.jar" />
<context id="mysql_table" targetRuntime="MyBatis3">
<commentGenerator>    
            <property name="suppressDate" value="true"/>    
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->    
            <property name="suppressAllComments" value="true"/>    
        </commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ct" userId="root"
password="" >
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.ct.ic.st.eu.entity"
targetProject="cms-core/src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件的包名和位置 -->
<sqlMapGenerator targetPackage="com.ct.ic.st.eu.dao"
targetProject="cms-core/src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.ct.ic.st.eu.dao" targetProject="cms-core/src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
        <!-- 要生成的实体和对应的来源表 -->
         <table tableName="t_log" domainObjectName="GameLog"  />
         <!--  
<table schema="???" tableName="???">
<columnOverride column="???" property="???" />
</table>
--> 
</context>
</generatorConfiguration>


注意问题:

1.这个配置标签一定要按照这个顺序(我就处过这个错,我把<javaTypeResolver>标签放到了<table>标签后,生成是报错,提示要按照指定的标签顺序写):按照<classPathEntry >,<context><commentGenerator> ,<jdbcConnection >,<javaTypeResolver>,<javaModelGenerator,<javaModelGenerator>...</<context>的顺序写,但不是所有的标签都必须有


2.关于targetPackage和targetProject的问题:

targetPackage是你的包名,一般是com开头的,比如com.xx.xx.dao或者com.xx.xx.service等等;

targetProject就要谨慎了,可以写项目的相对路径,也可以写绝对路径。本文我写的是相对路径,cms-core是项目名。写绝对路径就必须到你的硬盘上找到项目的工作空间上的你正在写代码的文件目录,比如我的是D:/ct/maven.1463711126644/cms-cms/cms-core/src/main/java,我的都在这里写的,注意 路径中/ 和 \ 的区别!

不要写以/或\开头的绝对路径


3.classPathEntry是你链接mysql数据库你要用的连接包,可以指定为你硬盘上的连接包


如果觉得还没解决你的问题,也来 参考别人的,附上几篇参考文章链接,放心,其中有些文章中包含generator插件下载链接:

http://maimode.iteye.com/blog/1539983/

http://www.mybatis.org/generator/configreference/xmlconfig.html

http://blog.sina.com.cn/s/blog_6f7265cf0102v7qa.html

http://www.cnblogs.com/yjmyzz/p/4210554.html

http://blog.csdn.net/ssrrxx111/article/details/51324571

单独利用mybatis generator在cmd命令生成,不需要安装插件 ,独立于eclipse,:http://www.cnblogs.com/smileberry/p/4145872.html

还有这个 http://blog.csdn.net/zhshulin/article/details/23912615

这个也是:http://blog.csdn.net/wyc_cs/article/details/9023117

http://javaeedevelop.iteye.com/blog/1726132


0 0
原创粉丝点击