mybatis generator默认采用追加方式生成。用过就知道,麻烦。更希望覆盖。
怎么办?
1.建一个类
public class OverwriteXmlPluginextends PluginAdapter {
@Override
public boolean validate(List warnings) {
return true;
}
@Override
public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {
try {
Field field = sqlMap.getClass().getDeclaredField("isMergeable");
field.setAccessible(true);
field.setBoolean(sqlMap,false);
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
2.修改xml配置
<context id="DB2Tables" targetRuntime="MyBatis3">
<property name="autoDelimitKeywords" value="true"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="com.main.fintech.util.OverwriteXmlPlugin"/>
<!--原来是下面这个,增加上面的。完事-->
<plugin type=" org.mybatis.generator.plugins.SerializablePlugin "/>