mybatis generator逆向工程自动生成带中文注释修改版(添加了实体类注释)文末附有git下载地址
解决问题:
原版的mybatis逆向工程生成的实体类没有,本版本主要就是反编译逆向工程源码后修改一个类的方法:
核心包mybatis-generator-core-1.3.2.jar包下的org\mybatis\generator\internal包下的类:DefaultCommentGenerator
原版:
import ***
public class DefaultCommentGenerator implements CommentGenerator {
***
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
if(!this.suppressAllComments) {
StringBuilder sb = new StringBuilder();
innerClass.addJavaDocLine("/**");
innerClass.addJavaDocLine(" * This class was generated by MyBatis Generator.");
sb.append(" * This class corresponds to the database table ");
sb.append(introspectedTable.getFullyQualifiedTable());
innerClass.addJavaDocLine(sb.toString());
this.addJavadocTag(innerClass, false);
innerClass.addJavaDocLine(" */");
}
}
}
修改后:
import ***
public class DefaultCommentGenerator implements CommentGenerator {
***
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
if(introspectedColumn.getRemarks() != null) {
field.addJavaDocLine("/** " + introspectedColumn.getRemarks() + "*/");
}
}
}
修改这个方法后,再生成的实体类每个字段就自动带上注释了,当然前提是你的表字段得有备注。
最终结果:
public class Applicant {
/** 岗位*/
private String position;
/** 级别*/
private Integer level;
/** 备注*/
private String comment;
下面附上完整的案例git地址:Mybatis逆向工程