美文网首页
Mybatis-Generator无法生成Example类问题

Mybatis-Generator无法生成Example类问题

作者: TDominator | 来源:发表于2019-10-17 17:50 被阅读0次

因为不了解配置文件的属性,这个小问题导致浪费了差不多一天的时间去网上找答案,可惜治标不治本,话不多说直接看代码

<?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>
    <!-- 你自己数据源jar包地址-->
    <classPathEntry location=".../sqljdbc4-4.0.jar" />
    <context id="mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
    
            <!--autoDelimitKeywords,当表名或者字段名为SQL关键字的时候,可以设置该属性为true,
        MBG会自动给表名或字段名添加分隔符-->
                
        <property name="autoDelimitKeywords" value="true"/>
        
        <!-- 生成的Java文件的编码 -->
        <property name="javaFileEncoding" value="UTF-8"/>

        <!-- 格式化java代码 -->
        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>     
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />  
        <commentGenerator>
            <property name="suppressDate" value="true" />
            <property name="suppressAllComments" value="true"/>
            <property name="addRemarkComments" value="true" />
            <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss" />          
        </commentGenerator> 
            
        <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
            connectionURL="jdbc:sqlserver://127.0.0.1:3306;DatabaseName=tableName"
            userId="yourName" password="yourPas">
        </jdbcConnection>
        
        
        
         <!-- 
            默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer   
            true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal   
        -->  
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- java 模型对象生成路径 -->
        <javaModelGenerator targetPackage="com.zaicent.entity"
            targetProject="zaicent-instore-entity">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
            <property name="useActualColumnNames" value="true" />
        </javaModelGenerator>
        <!-- java mapper生成路径 -->
        <sqlMapGenerator targetPackage="com.zaicent.mapper"
            targetProject="zaicent-instore-dao">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.zaicent.mapper" targetProject="zaicent-instore-dao">
            <property name="enableSubPackages" value="true" />
            <property name="rootInterface" value="com.zaicent.common.base.BaseMapper" />
        </javaClientGenerator>
        
        <table  tableName="zc_order" domainObjectName="ZcOrder"
                    enableCountByExample="true" enableUpdateByExample="true"
                    enableDeleteByExample="true" enableSelectByExample="true"
                    selectByExampleQueryId="true">
        </table>        
        
    </context>
</generatorConfiguration> 

这样写你会发现

enableCountByExample="true" enableUpdateByExample="true"
                    enableDeleteByExample="true" enableSelectByExample="true"
                    selectByExampleQueryId="true"

就算这么设置了也是没有用,就是死活生成不出来

当你了解配置文件targetRuntime属性后你会恍然大悟!!!
targetRuntime:
1,MyBatis3:默认的值,生成基于MyBatis3.x以上版本的内容,包括XXXBySample;
2,MyBatis3Simple:类似MyBatis3,只是不生成XXXBySample;
introspectedColumnImpl:类全限定名,用于扩展MBG

然后把配置文件改为

<context id="mysql" targetRuntime="MyBatis3" defaultModelType="flat">

就好拉。

相关文章

网友评论

      本文标题:Mybatis-Generator无法生成Example类问题

      本文链接:https://www.haomeiwen.com/subject/vzsvmctx.html