First, create a data script, the MySQL data script used here
drop table Filminfo;drop Table Filmtype;create table filminfo (filmid int primary key auto_increment, Filmname VARCHAR (not NULL), TYPEID int not NULL, ACTOR varchar (255), DIRECTOR varchar (ticketprice) ALTER TABLE Filminfo auto_increment = 10001;create table Filmtype (TYPEID int primary key auto_increment, Typena ME VARCHAR); ALTER TABLE filmtype auto_increment = 100001;insert into Filmtype (TYPENAME) VALUES (' Love movie '); insert INTO FIL Mtype (TYPENAME) VALUES (' action movie '), insert into Filmtype (TYPENAME) VALUES (' comedy '); insert into Filmtype (TYPENAME) VALUES (' Insert into Filmtype (TYPENAME) VALUES (' sci-fi films '), insert into Filmtype (TYPENAME) VALUES (' Horror films '), insert into Filmtype ( TYPENAME) VALUES (' cartoons '), insert into Filmtype (TYPENAME) VALUES (' other slices '); insert into Filminfo (Filmname,typeid,actor, Director,ticketprice) VALUES (' Avatar ', 10005, ' Sam Worthington, Zoe Saldana, Sigourney Weaver, Chow Moore, Laz Alonso, Giovanni Rebisi ', ' James Cameron ', Max); INSERT into Filminfo (Filmname,typeid,actor,director,ticketprice) vAlues (' Cat and Mouse ', 10007, ' Tom, Jerry ', ' William hanna,joseph Barbera '); insert into Filminfo (Filmname,typeid,actor,director, Ticketprice) VALUES (' Soldier teenager ', 10002, ' Jackie Chan, Leehom Wang, Liu Chengjun, Redatoms, Xu Dongmei, Du Yuming ', ' Ding ', ' n '); insert into Filminfo (Filmname,typeid,actor, Director,ticketprice) VALUES (' Great detective Sherlock Holmes ', 10002, ' Little Robert Downey, Jude Luo ', ' Guy Ritchie ', ' n '); insert into Filminfo (Filmname,typeid, Actor,director,ticketprice) VALUES (' All over the city ', 10001, ' Nicholas Tse Feng, Jacky Cheung, Rene, Vivian Hsu, Barbie ', ' Wing shya, FAI ', +); insert into Filminfo (filmname , Typeid,actor,director,ticketprice) VALUES (' Nineth District ', 10005, ' Chartos Copre, Jensen Coober, William Allen Yang ', ' Neill Blomkamp ', +); INSERT INTO Filminfo (Filmname,typeid,actor,director,ticketprice) VALUES (' Expendables 3 ', 10002, ' Sylvester Stallone, Jason Statham, Mel Gibson, Jet Li, Arnold Schwarzenegger, Dolph Lundgren ', ' pi Trick Houss ', (); Commit;select * from Filmtype;select * from Filminfo;
Operating commands under Linux:
Create DATABASE Cinema Character set Utf8;use cinema;source full path script file address
Generator.xml file
<?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><!--Database driver package location--><!- -<classpathentry location= "D:\software\lib\mysql-connector-java-5.1.21.jar"/>--><classpathentry location= "/home/a/workspace/mavenrepository/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar" /><context id= "Db2tables" targetruntime= "MyBatis3" ><commentgenerator><property name= " Suppressallcomments "value=" true "/></commentgenerator><!--database link URL, user name, password--><!--< Jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://localhost:3306/sy" userid= "Sypro" password= "Sypro" >--><jdbcconnection driverclass= "com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql:// Localhost:3306/cinema "userid=" root "password=" a "></jdbcconnection>≪javatyperesolver><property name= "Forcebigdecimals" value= "false"/></javatyperesolver><!-- Generate the package name and location of the model--><javamodelgenerator targetpackage= "Sy.model" targetproject= "/USR/DAY01/SRC" ><property Name= "Enablesubpackages" value= "true"/><property name= "Trimstrings" value= "true"/></ javamodelgenerator><!--generated map file package name and location--><sqlmapgenerator targetpackage= "sy.mapping" targetProject= "/ Usr/day01/src "><property name=" Enablesubpackages "value=" true "/></sqlmapgenerator><!-- Generate DAO's package name and location--><javaclientgenerator type= "Xmlmapper" targetpackage= "Sy.dao" targetproject= "/USR/DAY01/SRC" ><property name= "Enablesubpackages" value= "true"/></javaclientgenerator><!--to generate those tables ( Change TableName and Domainobjectname to--><table tablename= "Filminfo" domainobjectname= "Filminfo" Enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= " False "Selectbyexamplequeryid=" FalsE "/><table tablename=" Filmtype "domainobjectname=" Filmtype "enablecountbyexample=" false " Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False"/></context></generatorconfiguration>
To modify the location, the path of the driver package, the path of the MySQL package, the configuration of the linked database, the path of the generated package, and the last comment on the
<!--to generate those tables (you can change TableName and domainobjectname)--
Finally write a run script, create a bat suffix file under window, LINUB to create the sh suffix file
@echo ' Start ' Java-jar mybatis-generator-core-1.3.2.jar-configfile generator.xml-overwrite@echo ' End ' @pause
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MyBatis automatically generate Mapper,dao, map files