0.下载源码
地址:https://github.com/mybatis/generator/releases/tag/mybatis-generator-1.3.2
1.IDEA导入源码
2.修改Field.java
a.添加属性remark,同时添加getter,setter方法
b.修改getFormattedContent方法
public String getFormattedContent(int indentLevel) {
StringBuilder sb = new StringBuilder();
// 这个代码加在哪个位置,决定了你注释放在什么位置
if (remark != null && remark.length() > 0) {
sb.append("\t/**\n");
sb.append("\t * " + remark);
sb.append("\n");
sb.append("\t */");
sb.append("\n");
}
addFormattedJavadoc(sb, indentLevel);
addFormattedAnnotations(sb, indentLevel);
OutputUtilities.javaIndent(sb, indentLevel);
sb.append(getVisibility().getValue());
if (isStatic()) {
sb.append("static "); //$NON-NLS-1$
}
if (isFinal()) {
sb.append("final "); //$NON-NLS-1$
}
if (isTransient()) {
sb.append("transient "); //$NON-NLS-1$
}
if (isVolatile()) {
sb.append("volatile "); //$NON-NLS-1$
}
sb.append(type.getShortName());
sb.append(' ');
sb.append(name);
if (initializationString != null && initializationString.length() > 0) {
sb.append(" = "); //$NON-NLS-1$
sb.append(initializationString);
}
sb.append(';');
return sb.toString();
}
3. 修改AbstractJavaGenerator的getJavaBeansField方法
4.找到它的测试包,拷贝一个generatorConfigMyBatis3.xml,重命名generatorConfig_xxl.xml(自己取名字)。到MyBatisGeneratorTest里面再拷贝一个测试方法,重命名方法。Xml文件写自己刚刚拷贝的那个。
5.编辑自己的generatorConfig_xxl.xml文件。如下是我自己,供参考。
<generatorConfiguration>
<classPathEntry location="C:\Users\user\.m2\repository\mysql\mysql-connector-java\8.0.21\mysql-connector-java-8.0.21.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.XX:3306/u_indicator_client_test?serverTimezone=Asia/Shanghai"
userId="XXX" password="XXX">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="com.rank.management.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="com.rank.management.dao.mapper.nei" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成Dao类存放位置--> <!--/H*_/%Au?3br-->
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.rank.management.dao.nei" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成对应表及类名-->
<table tableName="Indicator" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
6.运行测试方法,然后就可以愉快的玩耍了