因?yàn)椴涣私馀渲梦募膶傩远痉眩@個(gè)小問題導(dǎo)致浪費(fèi)了差不多一天的時(shí)間去網(wǎng)上找答案毅弧,可惜治標(biāo)不治本哀卫,話不多說直接看代碼
<?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>
<!-- 你自己數(shù)據(jù)源jar包地址-->
<classPathEntry location=".../sqljdbc4-4.0.jar" />
<context id="mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<!--autoDelimitKeywords澜沟,當(dāng)表名或者字段名為SQL關(guān)鍵字的時(shí)候府蔗,可以設(shè)置該屬性為true晋控,
MBG會(huì)自動(dòng)給表名或字段名添加分隔符-->
<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>
<!--
默認(rèn)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>
這樣寫你會(huì)發(fā)現(xiàn)
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true"
就算這么設(shè)置了也是沒有用赡译,就是死活生成不出來
當(dāng)你了解配置文件targetRuntime屬性后你會(huì)恍然大悟!2幻蝌焚!
targetRuntime:
1,MyBatis3:默認(rèn)的值誓斥,生成基于MyBatis3.x以上版本的內(nèi)容只洒,包括XXXBySample;
2劳坑,MyBatis3Simple:類似MyBatis3毕谴,只是不生成XXXBySample;
introspectedColumnImpl:類全限定名泡垃,用于擴(kuò)展MBG
然后把配置文件改為
<context id="mysql" targetRuntime="MyBatis3" defaultModelType="flat">
就好拉析珊。