将org.mybatis.generator.interal.DefaultCommentGenerator类的addFieldComment方法重写,代码如下:
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { if (suppressAllComments) { return; } StringBuilder sb = new StringBuilder(); field.addJavaDocLine("/**"); //$NON-NLS-1$ // field.addJavaDocLine(" * This field was generated by MyBatis Generator."); //$NON-NLS-1$ sb.append(" * "); //$NON-NLS-1$ sb.append(introspectedColumn.getRemarks()); sb.append(",所属表字段为"); sb.append(introspectedTable.getFullyQualifiedTable()); sb.append('.'); sb.append(introspectedColumn.getActualColumnName()); field.addJavaDocLine(sb.toString()); // addJavadocTag(field, false); field.addJavaDocLine(" */"); //$NON-NLS-1$ }
然后编译后,在放入jar包。
在mybatis生成代码的xml配置文件中,
jdbcConnection里面加:
<!-- oracle获取注释 --> <property name="remarksReporting" value="true"></property>
commentGenerator里面加:
<property name="javaFileEncoding" value="UTF-8"/>
为了防止生成的文件是gbk编码,需要将eclipse或者idea的配置内存的那个文件,打开,加一句话:
-Dfile.encoding=UTF-8