Mybatis generator automatically generates model, Dao, and mapper examples

Source: Internet
Author: User
Tags xml example

Mybatis-generator-core-1.3.2:

Https://code.google.com/p/mybatis/downloads/list? Can = 3 & Q = product % 3 dgenerator

Generator. xml example:

<? 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: \ mysql-connector-java-5.0.4.jar "/> <context ID =" mysql2tables "targetruntime =" mybatis3 "> <jdbcconnection driverclass =" com. mySQL. JDBC. driver "connectionurl =" JDBC: mysql: // 192.168.0.5: 3306/test "userid =" root "Password =" root "> </jdbcconnection> <javatyperesolver> <property name =" forcebigdecimals "value =" false "/> </javatyperesolver> <javamodelgenerator targetpackage = "com. test. model "targetproject =" src "> <property name =" enablesubpackages "value =" true "/> <property name =" trimstrings "value =" true "/> </javamodelgenerator> <sqlmapgenerator targetpackage = "com. test. mapper "targetproject =" src "> <property name =" enablesubpackages "value =" true "/> </sqlmapgenerator> <javaclientgenerator type =" xmlmapper "targetpackage =" com. test. mapper "targetproject =" src "> <property name =" enablesubpackages "value =" true "/> </javaclientgenerator> <Table schema =" test "tablename =" test "domainobjectname = "test" Success = "false" enableupdatebyexample = "false" enabledeletebyexample = "false" enableselectbyexample = "false" selectbyexamplequeryid = "false"> </table> </context> </generatorconfiguration>

Example of mybatisgeneratorutil. Java:

Package COM. utils; import Java. io. file; import Java. io. ioexception; import Java. SQL. sqlexception; import Java. util. arraylist; import Java. util. list; import Org. mybatis. generator. API. mybatisgenerator; import Org. mybatis. generator. config. configuration; import Org. mybatis. generator. config. XML. configurationparser; import Org. mybatis. generator. exception. invalidconfigurationexception; import Org. mybatis. generator. exception. xmlparserexception; import Org. mybatis. generator. internal. defaultshellcallback; public class mybatisgeneratorutil {public static void main (string [] ARGs) {try {system. out. println ("start generator... "); List <string> warnings = new arraylist <string> (); Boolean overwrite = true; file configfile = new file (mybatisgeneratorutil . Class. getresource ("/generator. xml"). GetFile ()); Configurationparser CP = new configurationparser (warnings); configuration Config = CP. parseconfiguration (configfile); defaultshellcallback callback = new defaultshellcallback (overwrite); mybatisgenerator = new mybatisgenerator (config, callback, warnings); mybatisgenerator. generate (null); system. out. println ("End generator! ");} Catch (ioexception e) {e. printstacktrace ();} catch (xmlparserexception e) {e. printstacktrace ();} catch (invalidconfigurationexception e) {e. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();} catch (interruptedexception e) {e. printstacktrace ();}}}

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.