1. 程式人生 > >mybatis generator 生成資料庫註釋等問題

mybatis generator 生成資料庫註釋等問題

mybatis程式碼生成器生成資料庫的註釋,找了半天沒有找到非常詳細可用的,於是我打算自己整理一份,分享出來,以下是本人親身經歷的問題處理流程,實踐有效。 前提:可以使用一般的mybatis generator 程式碼生成器 及配置各種基本註解,這些不是本文重點,不再過多敘述 1.在網上找了mybatis-generator-core 原始碼,通過分析後改動,原始碼裡把資料庫的表字段註釋給注掉了,所以只配置generatorConfig.xml 這個是不管作用的。 下載原始碼 https://github.com/ppj117/mybatis-generator-core  把新增 資料庫註釋的地修改一下 在原始碼裡找到 org.mybatis.generator.internal.DefaultCommentGenerator類,這個類中addClassComment這個方法 是標註中文註釋的。為了使addClassComment生效,還得找到org.mybatis.generator.codegen.mybatis3.model.BaseRecordGenerator類,在大約60行的地方,在commentGenerator.addJavaFileComment(topLevelClass);後加一句:
commentGenerator.addClassComment(topLevelClass, introspectedTable,false); 這樣自己的方法就呼叫到了,說明一下,仔細看一下原始碼,會發現DefaultCommentGenerator類,會發現addClassComment方法有兩個,一個加了boolean markAsDoNotDelete引數,一個沒有加,你這裡呼叫的如果不加false引數,就改DefaultCommentGenerator類中兩個引數的addClassComment方法,我的樣例中你會發現方法中傳了引數也不管用,因為真正的原始碼中是有這麼一行的 然後addJavadocTag方法中是這麼呼叫的
這樣就把原始碼的註釋給置為可用狀態。 2.重新打包 生成 mybatis-generator-core-1.3.2.jar 後 ,執行提示沒有主清單, 打好jar包之後還需要更改清單檔案的. 開啟生成的jar,裡面有一個MANIFEST.MF的檔案把它開啟, 然後有一行Main-Class,沒有就加上。如: Main-Class: org.mybatis.generator.api.ShellRunner 3.命令執行generatorConfig.xml檔案,執行之後可能會提示 [ERROR] XML Parser Error on line 34: 元素型別為 "context" 的內容必須匹配 "(property*,plugin*,commentGenerator?,(connectionFactory|jdbcConnection),javaTypeResolver?,javaModelGenerator,sqlMapGenerator?,javaClientGenerator?,table+)"。
因為generatorConfig.xml 這個配置檔案裡的 屬性資訊沒有按照上述順序排列 4.如果想擴充套件,生成dao介面或者xml的名字,可以做如果操作 mybatis generator Mapper Dao PointDao.xml 和 PointMapper.xml 設定 在原始碼IntrospectedTable 類中 calculateJavaClientAttributes 這個方法裡設定mapper or dao

//包含處理 Mapper 介面和 SqlProvider 的程式碼protected void calculateJavaClientAttributes() { //...}//包含處理 Mapper.xml 的程式碼protected String calculateMyBatis3XmlMapperFileName() {}

下面提供一份我修改過可用的原始碼及下載工具,有任何問題可以找我

原始碼及生成工具下載地址

http://download.csdn.net/detail/hf709363456/9901489