MyBatis generator (postgres)-----產生Dto、Dao、Mapping

來源:互聯網
上載者:User

一.eclipse Mybatis generator 外掛程式安裝
二.MyBatis generator (postgres)—–產生Dto、Dao、Mapping

一.eclipse Mybatis generator 外掛程式安裝
1.自動安裝
—-開啟eclipse,點擊Help>Software Update
—-選擇 “Available Software” 標籤,點擊 “Add Site” 按鈕
—-輸入以下資訊:
Location:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
—-點擊ok,自動進入 “mybatis generator Feature”
—-點擊“install”按鈕進行安裝。。。。mybatis generator 外掛程式安裝完成

2.手動安裝
—-教程http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html
—-外掛程式下載http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html

二.MyBatis generator (postgres)—–產生Dto、Dao、Mapping
由於MyBatis屬於一種半自動的ORM架構,所以主要的工作將是書寫Mapping對應檔,但是由於手寫對應檔很容易出錯,所以查資料發現有現成的工具可以自動產生底層模型類、Dao介面類甚至Mapping對應檔.

—–創建表
CREATE TABLE worker (
id varchar(50) NOT NULL,
username varchar(18) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
password varchar(18) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;

—–配置generator config
generatorConfig.xml

<?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="/home/peng.zhang/zpeng/sources/myjars/postgresql-9.4-1201.jdbc4.jar" />    <context id="context1">        <jdbcConnection driverClass="org.postgresql.Driver"            connectionURL="jdbc:postgresql://127.0.0.1:5432/postgres" userId="postgres"            password="123456" />        <!-- 產生模型的包名和位置-->         <javaModelGenerator targetPackage="com.travelzen.entity"            targetProject="MybatisTOPostgresql" />        <!-- 產生對應檔的包名和位置-->         <sqlMapGenerator targetPackage="mybatis"            targetProject="MybatisTOPostgresql" />        <!-- 產生DAO的包名和位置-->        <javaClientGenerator            targetPackage="com.travel.dao"            targetProject="MybatisTOPostgresql"            type="XMLMAPPER" />        <!-- 要產生哪些表-->          <table tableName="worker" domainObjectName="WorkerDto" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>          <!-- <table schema="zpeng" tableName="stu" domainObjectName="Student"            enableSelectByPrimaryKey="true" enableUpdateByPrimaryKey="true"            enableDeleteByPrimaryKey="true" enableSelectByExample="false"            enableDeleteByExample="false" enableCountByExample="false"            enableUpdateByExample="false">            <columnOverride column="" property="" />        </table> -->    </context></generatorConfiguration>

—–產生(兩種方式)
1.右鍵設定檔運行:

2.命令:java -jar /Users/liqiu/git/study/web/soft/mybatis-generator-core-1.3.2/lib/mybatis-generator-core-1.3.2.jar -configfile /Users/liqiu/git/study/web/soft/mybatisGeneratorConfig.xml -overwrite

*無法正確產生看這裏:
http://www.cnblogs.com/AloneSword/p/3412236.html

1.XML Parser Error on line 13: XML 文檔結構必須從頭至尾包含在同一個實體內。
貌似設定檔不能加註釋。

2.Unexpected error while running MyBatis Generator. Exception getting JDBC Driver
查閱generator官方文檔發現指定Jar包路徑即可

3.eneration Warnings Occured Table configuration with catalog null, schema null, and table T_LOGIN did not resolve to any tables
忘了建表,資料庫中沒表當然解析不了………建立表,解析成功,毫無壓力

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.