配置需注意2点,
1.对于匹配所有表用%,多表配合使用_和%,这个和SQL Like查询模糊匹配方法一致
2.配置报错的话,提示如下:标黄的部分其实是正则表达式
The content of element type "context" is incomplete, it must match
"(property*,plugin*,commentGenerator?,(connectionFactory|
jdbcConnection),javaTypeResolver?,javaModelGenerator,sqlMapGenerator?,javaClientGenerator?,table+)".
真实项目范例:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration 3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 6 <generatorConfiguration> 7 <!--<properties resource="application.properties"/>--> 8 9 <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> 10 <property name="beginningDelimiter" value="`"/> 11 <property name="endingDelimiter" value="`"/> 12 13 <!-- 数据源配置开始 --> 14 <plugin type="tk.mybatis.mapper.generator.MapperPlugin"> 15 <property name="mappers" value="com.qfpie.server.util.QkMapper"/> 16 </plugin> 17 <jdbcConnection driverClass="com.mysql.jdbc.Driver" 18 connectionURL="jdbc:mysql://172.**.**.**:3306/qone" 19 userId="qkapp" 20 password="*********"> 21 </jdbcConnection> 22 23 <javaModelGenerator targetPackage="com.qfpie.server.model.qone" targetProject="src/main/java"/> 24 <sqlMapGenerator targetPackage="mapper.qone" targetProject="src/main/resources"/> 25 <javaClientGenerator targetPackage="com.qfpie.server.mapper.mysql.qone" targetProject="src/main/java" 26 type="XMLMAPPER"/> 27 28 <!-- 数据源配置结束 --> 29 30 <table tableName="cobra_text" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"> 31 <!--% 表示全部表--> 32 <!--mysql 配置--> 33 <generatedKey column="ID" sqlStatement="Mysql" identity="true"/> 34 <!--oracle 配置--> 35 <!-- <generatedKey column="ID" sqlStatement="select SEQ_{1}.nextval from dual" identity="false" type="pre"/> --> 36 </table> 37 </context> 38 </generatorConfiguration>