MyBatis Generator 根據資料庫表結構反向生成實體類、Mapper 介面與 XML 映射檔。本專案基於 1.3.5 版本,新增詳細中文註釋並擴充實用功能,原始碼託管於 GitHub。
org.mybatis.generator.plugins.ToStringPlugin:自動生成 toString() 外掛org.mybatis.generator.plugins.MapperConfigPlugin:Mapper 配置外掛org.mybatis.generator.api.ShellRunner:主程式入口org.mybatis.generator.config.xml.ConfigurationParser:配置檔解析器org.mybatis.generator.config.Context:上下文封裝核心類在 FullyQualifiedTable 新增 remark 欄位,於 DatabaseIntrospector.calculateIntrospectedTables() 中執行 SQL 獲取表註釋:
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"SHOW TABLE STATUS LIKE '" + tableName + "'");
while (rs.next()) {
table.setRemark(rs.getString("COMMENT"));
}
rs.close();
stmt.close();
新增 addExampleClassComment(TopLevelClass) 方法,為 Example 類別生成標準化註釋。
優化 IntrospectedTableMyBatis3Impl.getGeneratedJavaFiles(),支援更靈活的檔案生成控制。
入口 ShellRunner 及核心流程全部補充中文註釋,註釋模板可於 DefaultCommentGenerator 客製化。
GitHub:mybatis-generator-core-chinese-annotation-1.3.5
此修訂版大幅降低生成代碼的二次修改成本,提升團隊開發效率。