mybatis 自動生成代碼

MyBatis中,可以使用Generator自動生成代碼,包括DAO層、 MODEL層 、MAPPING SQL映射文件。

第一步:下載MyBatis的Generator工具
htt p:/ /mybati s.gith ub.i o/generator/

第二步:配置自動生成代碼所需的XML配置文件,例如(generator.xml)

將這個文件保存至你下載的mybatis-generator-core-1.3.2文件夾下

第三步:進入XML配置文件(generator.xml)所在的的目錄並執行命令:
Dos代碼
java -jar E:\mybatis-generator-core-1.3.2\lib\mybatis-generator-core-1.3.2.j ar -configfile generator.xml -overwrite

mybatis generator eclipse插件的安裝

打開eclipse,點擊Help>Software Update
選擇 "Available Software" 標籤,點擊 "Add Site" 按鈕
輸入以下信息:
Location:htt p:/ /mybatis.googleco de.c om/svn/sub-projects/gen erator/trunk/eclipse/UpdateSite/
點擊ok,自動進入"mybatis generator Feature"
點擊“install”按鈕進行安裝。。。。mybatis generator 插件安裝完成

配置Mybatis Generator不要生成Example類
Mybatis Generator默認設置會生成一大堆羅哩羅嗦的Example類,主要是用各種不同的條件來操作數據庫,大部分是用不到的,用到的時候手工修改mapper和接口文件就行了。

<</code>table

schema="general"

tableName="tb_table_name"

domainObjectName="EntityName"

enableCountByExample="false"

enableUpdateByExample="false"

enableDeleteByExample="false"

enableSelectByExample="false"

selectByExampleQueryId="false"

>

name="useActualColumnNames"

value="true"/>

</</code>table>
這樣生成的mapper和dao接口就清爽多了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章