MyBatis Generator (postgres)-----Generate DTO, Dao, Mapping

Source: Internet
Author: User
Tags generator postgresql xml parser

one. Eclipse MyBatis Generator Plug-in installation
two. MyBatis Generator (Postgres)-– generates DTO, Dao, Mapping

One. Eclipse MyBatis Generator Plug-in installation
1. Self-motion installation
--Open Eclipse, click Help>software Update
--Select the "Available Software" tab and click the "Add Site" button
--Enter the following information:
location:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/updatesite/
--Click OK, automatically enter "MyBatis generator Feature"
--click the "Install" button to install .... MyBatis Generator Plug-in installation complete

2. Manual Installation
--Tutorial Http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html
--The plugin download http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html

Two. MyBatis Generator (Postgres)-– generates DTO, Dao, Mapping
Because MyBatis belongs to a semi-automatic ORM framework, the main job will be to write the mapping mapping file, but because the handwriting mapping file is prone to error, the data discovery has off-the-shelf tools to automatically generate the underlying model classes, DAO interface classes, and even mapping mapping files.

-– Create a table
CREATE TABLE Worker (
ID varchar not NULL,
Username varchar (km) CHARACTER SET UTF8 COLLATE utf8_bin DEFAULT NULL,
Password varchar (%) DEFAULT NULL,
PRIMARY KEY (ID)
) Engine=innodb DEFAULT Charset=utf-8;

-– Configuration Generator Config
Generatorconfig.xml

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <classpathentry locat
        ion= "/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/postgre S "userid=" Postgres "password=" 123456 "/> <!--generate the package name and location of the model--> Targetpackage= "com.travelzen.entity" targetproject= "Mybatistopostgresql"/> <!--generate the package name and location of the mapping file--& 
        Gt <sqlmapgenerator targetpackage= "MyBatis" targetproject= "Mybatistopostgresql"/> <!--generate the package name for DAO
           and position--> <javaclientgenerator targetpackage= "Com.travel.dao" targetproject= "Mybatistopostgresql" type= "Xmlmapper"/> <!--which tables to generate--> t Ablename= "worker" Domainobjectname= "Workerdto" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table> ;! --<table schema= "Zpeng" Tablename= "Stu" Domainobjectname= "Student" enableselectbyprimarykey= "true" Enableu Pdatebyprimarykey= "true" enabledeletebyprimarykey= "true" enableselectbyexample= "false" Enabledelet Ebyexample= "false" enablecountbyexample= "false" enableupdatebyexample= "false" > <columnoverri De column= "" property= ""/> </table>--> </context> </generatorConfiguration>

-– generation (two ways)
1. Right-click Configuration file to run:

2. Order: 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

* Unable to correctly generate look here:
Http://www.cnblogs.com/AloneSword/p/3412236.html

1.XML Parser Error on line 13:xml document structure must be included in the same entity from beginning to beginning.
Looks like the configuration file cannot be commented on.

2.Unexpected error while running MyBatis generator. Exception getting JDBC Driver
Check Generator Official document Discovery specify jar package path

3.eneration warnings occured Table configuration with catalog null, schema NULL, and Table T_login did Tables
Forgot to build the table, no table in the database of course can not resolve ... CREATE TABLE, parse success, no pressure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.