1. 程式人生 > >MyBatis Generator Mybatis程式碼生成介紹

MyBatis Generator Mybatis程式碼生成介紹

Mybatis官方提供了程式碼生成工具,這裡是官方網站: http://mybatis.github.io/generator/index.html

可以自動生成 Java POJOs, Mapper.xml, Mapper.java。

1、下載 mybatis-generator-core-1.3.2.jar  google上有

2、下載 myeclipse外掛 https://github.com/mybatis/generator/tree/master/eclipse/UpdateSite

3、下載configure.xml 配置檔案 http://mybatis.github.io/generator/configreference/xmlconfig.html

下載完成後先安裝MyEclipse外掛,安裝好以後新建一個專案,然後mybatis-generator-core-1.3.2.jar 扔到lib裡面去, 然後將configure.xml放到src下面。

複製程式碼
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" 
> <generatorConfiguration> <!-- 根據不同資料庫選擇驅動 注意路徑需要改成你自己的路徑 --> <!--<classPathEntry location="D:\Workspaces\MyEclipse 10\CodeGenerator\WebRoot\WEB-INF\lib\ojdbc14.jar" /> --> <classPathEntry location="E:\Workspaces\MyEclipse10\CodeGenerator\WebRoot\WEB-INF\lib\jtds-1.2.jar"
/> <!-- id隨便起沒什麼意義 --> <context id="contextOne" targetRuntime="MyBatis3" defaultModelType="conditional"> <!-- 控制生成註釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="suppressDate" value="true" /> </commentGenerator> <!-- ORACLE 的連線串 <jdbcConnection driverClass="oracle.jdbc.OracleDriver" connectionURL="jdbc:oracle:thin:@192.168.1.24:1521:ORCL" userId="dloa" password="dloa"> </jdbcConnection> --> <!-- MSSQL2008 --> <jdbcConnection driverClass="net.sourceforge.jtds.jdbc.Driver" connectionURL="jdbc:jtds:sqlserver://124.95.165.217/ZhengFuBan" userId="sa" password="[email protected]#"> </jdbcConnection> <javaTypeResolver type="com.code.generator.Convert" /> <!-- 實體類 (targetPackage="com.framework.code.domain"這裡是生成的包名,要和程式實際包名一致) --> <javaModelGenerator targetPackage="com.framework.code.domain" targetProject="CodeGenerator"> </javaModelGenerator> <!-- mapper.xml (targetPackage="com.framework.code.domain"這裡是生成的包名,要和程式實際包名一致) --> <sqlMapGenerator targetPackage="com.framework.code.mapper" targetProject="CodeGenerator" /> <!-- mapper.java (targetPackage="com.framework.code.domain"這裡是生成的包名,要和程式實際包名一致) --> <javaClientGenerator targetPackage="com.framework.code.mapper" targetProject="CodeGenerator" type="XMLMAPPER" /> <!-- tableName="你要生成的資料庫表名" --> <table schema="" tableName="TEST" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table> </context> </generatorConfiguration>
複製程式碼

然後在配置檔案上右鍵-執行就可以了。

安裝好外掛就帶這個右鍵功能了,然後就可以生成程式碼了

相關推薦

MyBatis Generator Mybatis程式碼生成介紹

Mybatis官方提供了程式碼生成工具,這裡是官方網站: http://mybatis.github.io/generator/index.html 可以自動生成 Java POJOs, Mapper.xml, Mapper.java。 1、下載 mybatis-ge

MyBatis Generator程式碼自動生成工具 generatorConfig.xml配置檔案詳解

MyBatis Generator官網地址:http://www.mybatis.org/generator/index.html MyBaris Generator中文地址:http://mbg.cndocs.ml/ 在MBG中,最主要也最重要的,就是generatorConfig.xml

mybatis-generator命令列生成程式碼

目錄檔案如下: generator.xml檔案如下: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBati

Maven整合外掛mybatis-generator(mybatis自動生成實體程式碼的外掛)使用

mybatis-generator這個外掛有什麼用處 這個外掛是通過連線資料庫,根據資料庫中的表來自動生成model、資料庫控制層介面以及對應的xml檔案的一個外掛 怎麼使用這個外掛 現在來談談怎麼使用這個外掛,既然式maven下的外掛,所以第一步先建立一個maven的專案,然後再pom

解決mybatis-generator mybatis逆向工程生成程式碼時tinyint(1)變成boolean型別

最近在使用mybatis-generator mybatis逆向工程生成程式碼時,遇到一個問題,資料庫表中有個欄位為 isEnabled  tinyint(1)  NOT NULL  是否啟動: 0 不啟動,1 啟用 在使用逆向工程生成的程式碼中,這個欄位變成了

在IDEA中使用MyBatis Generator逆向工程生成程式碼

一、配置Maven pom.xml 檔案 在pom.xml增加以下外掛: <build> <finalName>aaa</finalName> <plugins>

mybatis 自動生成DB程式碼一場之 Failed to retrieve plugin descriptor for org.mybatis.generator:mybatis-generator

1.異常描述 使用mybatis自動生成DB程式碼的時候報下面的異常 [WARNING] [WARNING] Some problems were encountered while building the effective settings [WARNI

MyBatis Generator——Maven模式生成程式碼

使用Maven執行MyBatis Generator   MyBatis Generator (MBG)包含一個Maven外掛,用於整合到Maven構建中。用於將其整合到Maven構建中。按照約定策略與Maven的配置保持一致,在Maven構建中包含

在IDEA中使用MyBatis Generator逆向工程生成程式碼 實踐

第一步:在pom檔案下加入 <plugin> <groupId>org.mybatis.generator</groupId> <artifactId

Maven外掛-mybatis-generator(mybatis自動生成實體程式碼的外掛)

        3.1 配置 1在pom.xml中做兩處配置 1.1配置dependency    要使用generator外掛自動生成相關檔案,需要引入mybatis-generator-core這個包,在<dep

Maven外掛之mybatis-generator(mybatis自動生成實體程式碼的外掛)

        3.1 配置 1在pom.xml中做兩處配置 1.1配置dependency    要使用generator外掛自動生成相關檔案,需要引入mybatis-generator-core這個包,在<dependencys>中加入

利用Mybatis-generator工具自動生成程式碼

配置JAVA環境變數; 執行生成程式碼之前,我們須要做的準備工作。  1、新建一個資料夾,作為我們的工作空間,例如: D:\generator 注意:這裡的路徑不要帶有中文字元,這是規範,即使帶有中文字元不會出什麼問題。 2、在 generator 這路徑下 (1)放置 m

mybatis-generator-修改原始碼生成自己想要的程式碼

前言 雖然mybatis-generator能生成dao,mapper,xml等檔案,但是生成的程式碼也不是完全通用,所以這裡我們要的mybatis-generator-core原始碼進行修改。 場景 1.生成自己想要的註釋 /** * 使用者資訊

mybatis-generator-mysql程式碼自動生成工具

流程:    1、匯入MybatisGenerator專案,在build path中修改jar包位置(mybatis-generator-core-1.3.2和mysql-jdbc)    2、修改generator.xml檔案        a.修改資料庫連線資訊<!

在idea中使用Mybatis-generator外掛快速生成程式碼

1、引入外掛 <plugin> <groupId>org.mybatis.generat

在IDEA中使用MyBatis Generator逆向工程生成代碼

classpath 生成器 targe base time jar包 選項 操作 ava 本文介紹一下用Maven工具如何生成Mybatis的代碼及映射的文件。 一、配置Maven pom.xml 文件 在pom.xml增加以下插件: <build>

Mybatis Generator的model生成中文註釋,支持oracle和mysql(通過實現CommentGenerator接口的方法來實現)

req gre files Language default dom sel setter ini 在看本篇之前,最好先看一下上一篇通過實現CommentGenerator接口的方法來實現中文註釋的例子,因為很多操作和上一篇基本是一致的,所以本篇可能不那麽詳細. 首先說一

MyBatis學習總結(四)——MyBatis快取與程式碼生成

 一、MyBatis快取 快取可以提高系統性能,可以加快訪問速度,減輕伺服器壓力,帶來更好的使用者體驗。快取用空間換時間,好的快取是快取命中率高的且資料量小的。快取是一種非常重要的技術。 1.0、再次封裝SqlSessionFactoryUtils 為了配置快取的學習我們將工具類再次封裝。 原SqlS

MyBatis Generator (自動生成工具) 詳解

MyBatis Generator中文文件地址: 該中文文件由於儘可能和原文內容一致,所以有些地方如果不熟悉,看中文版的文件的也會有一定的障礙,所以本章根據該中文文件以及實際應用,使用通俗的語言來講解詳細的配置。 本文中所有節點的連結都是對

Mybatis Generator外掛自動生成xml對映檔案追加與覆蓋的問題

參考: mybatis generator 覆蓋xml檔案 使用Mybatis Generator可以快速根據資料庫中已經建立好的表來建立mybatis程式碼,但是一旦資料庫的表結構發生變動,就要重新執行Mybatis Generator外掛。每次執行都會在已經生成的xml後追加一遍所有的