First, install the Mybatis_generator plugin to eclipse
1. Method 1:
Download the Mybatis_generator_1.3.1.zip and copy the features and Plugins2 folders to the Eclipse installation directory after decompression.
2. Method 2:
Help->install New Software Input plugin address: http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
Specific installation process can refer to Baidu.
Ii. creation of 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> <!--specifies the path to the drive file (or it can be a relative path) - <Classpathentry Location= "F:\JAVA\java_jar\mysql_driver\mysql-connector-java-5.1.0-bin.jar"/> <ContextID= "Db2tables"> <!--Suppressdate:false When the time flag is turned on, true when closing - <!--Suppressallcomments:false Open Comment when true to close comment - <Commentgenerator> < Propertyname= "Suppressdate"value= "true"/> < Propertyname= "Suppressallcomments"value= "true"/> </Commentgenerator> <!--database URL, user name, password - <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://127.0.0.1/blog"userId= "root"Password="***" /> <!--MyBatis specifically used to deal with numeric and decimal types of strategies - <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false"/> </Javatyperesolver> <!--entity classes generate configurations, target packages and projects, note that the MAVEN engineering structure directory should be with the project name and Src/main/java - <JavamodelgeneratorTargetpackage= "Com.blog.pojo"Targetproject= "Blog/src/main/java"> < Propertyname= "Enablesubpackages"value= "true"/> < Propertyname= "Trimstrings"value= "true"/> </Javamodelgenerator> <!--mapper.xml file generation configuration, target package and engineering, note that the MAVEN engineering structure directory should be with the project name and Src/main/java - <SqlmapgeneratorTargetpackage= "Com.blog.mapping"Targetproject= "Blog/src/main/java"> < Propertyname= "Enablesubpackages"value= "true"/> </Sqlmapgenerator> <!--interface generation configuration, target package and engineering, note that the MAVEN engineering structure directory should be with the project name and Src/main/java - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.blog.dao"Targetproject= "Blog/src/main/java"> < Propertyname= "Enablesubpackages"value= "true"/> </Javaclientgenerator> <!--Specify the generated table: TableName is the table name in the database Domainobjectname is the entity class name - <!--MyBatis Generator Code generator generates a EXAMLE class for the table entity class by default, you can change the generator's configuration to false to avoid generating the Examle class - <!--Columnoverride: If it does not exist, the entity class is created by default by the field type in the database and, if present, the Entity class field is created by the name and type specified below. - <!--Ignorecolumn: This property is not created in the entity class - <TableTableName= "Blog_user"Domainobjectname= "User"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"> <!--<columnoverride column= "username" property= "name"/> <ignorecolumn column= "password"/> <columnoverride column= "Age" javatype= "String" ></columnOverride> - </Table> </Context></generatorconfiguration>
Third, click Generatorconfig.xml, select Generate Mybatis/ibatis arifacts, generate corresponding dao,mapper,entity.
Attach the Project catalogue:
Mybatis-generator automatically generate dao,mapper,entity