一开始从网上找的generatorConfig.xml内容如下:
<generatorConfiguration>
<properties resource="mybatis-generator/mybatisGeneratorInit.properties"/>
<span class="token comment"><!-- 一个数据库一个context --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>context</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>MysqlTables<span class="token punctuation">"</span></span> <span class="token attr-name">targetRuntime</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>MyBatis3Simple<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
<span class="token comment"><!-- 自动识别数据库关键字,默认false,如果设置为true,根据SqlReservedWords中定义的关键字列表;
一般保留默认值,遇到数据库关键字(Java关键字),使用columnOverride覆盖 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>autoDelimitKeywords<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token comment"><!-- 生成的Java文件的编码 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>javaFileEncoding<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>utf-8<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token comment"><!-- beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号; --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>beginningDelimiter<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>`<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>property</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>endingDelimiter<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>`<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
...
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>context</span><span class="token punctuation">></span></span>
...
</generatorConfiguration>
发现运行生成代码的maven插件后,Mapper.java和Mapper.xml中都没有Selective结尾的方法(insertSelective、updateByPrimaryKeySelective)。
后来发现是context标签的targetRuntime属性的原因,将其设置为MyBatis3
即可。
更详细的Mybatis-generator插件配置请参考:
1.https://www.jianshu.com/p/e09d2370b796
2.https://github.com/zouzg/mybatis-generator-gui
原文地址:https://blog.csdn.net/lzufeng/article/details/86716095